Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Multiple assertions develop #379

Merged
merged 65 commits into from
Feb 20, 2018

Conversation

basz
Copy link
Collaborator

@basz basz commented Feb 18, 2018

Implements #320 for develop branch

  • does so without performance loss if not used
  • assertion sets may be nested with different conditions
  • does so lazily for each condition
    • an AND condition will break early as soon as one assertions fails
    • an OR condition will break early as soon as one assertions succeed
  • assertions are cached, so a next call won't require to construct an assertion or AssertionSet.

documentation forthcoming

@basz basz requested a review from prolic February 18, 2018 20:56
@basz
Copy link
Collaborator Author

basz commented Feb 18, 2018

no sure why this PR also show commits already pulled into develop.

review request is from commit e7fd215 and forward

@basz basz mentioned this pull request Feb 18, 2018
Copy link
Contributor

@svycka svycka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure why unrelated changes were added for example CS check and Travis config to this PR. Also maybe we can require php7.1 and we could use void return type as we now use it. I don't know why so many unrelated changes are in this PR maybe that's what you said that some commits from develop branch is here. but then maybe rebase is required?

* @return AuthorizationService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function createService(ServiceLocatorInterface $serviceLocator): AuthorizationService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for ServiceManager v2 and we no longer support it so can be removed

* @return ModuleOptions
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function createService(ServiceLocatorInterface $serviceLocator): ModuleOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also not used anymore and in other factories also...

@@ -40,15 +42,15 @@ class ObjectRepositoryRoleProviderFactory implements FactoryInterface
protected $options = [];

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function __construct(array $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this constructor?

*/
public function __construct(array $options = [])
{
$this->setCreationOptions($options);
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function setCreationOptions(array $options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$options from __invoke(ContainerInterface $container, $requestedName, array $options = null) method can be used instead this method also from SM v2

* @return RoleService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function createService(ServiceLocatorInterface $serviceLocator): RoleService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

@@ -1,4 +1,6 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that git show that this file was renamed test/Asset/Permission.php → src/Role/Role.php but not sure if that's important :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there is some git plugin that fixes that, but I forgot the name.

/**
* @var array
*/
protected $invokableClasses = [
InMemoryRoleProvider::class => InMemoryRoleProvider::class
protected $aliases = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need those aliases? I think FCQN is what everyone uses.

{
return 'role-with-permission-method';
}
public function hasPermission($permission)

public function hasPermission(string $permission): bool
{
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be something like return in_array($permission, $this->getPermissions(), true);? This may is test asset but can lead to problems later if someone will assume that this is valid role

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone has a problem when using a MockRole from TestAsset in production, he deserves this problem :)

@@ -36,10 +40,10 @@ public function testAssertModuleDefaultOptions()
public function testSettersAndGetters()
{
$moduleOptions = new ModuleOptions([
'guest_role' => 'unknown',
'role_provider' => [],
'guest_role' => 'unknown',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like those spaces but i guess that's not for me to decide :D

/**
* Simple implementation for a hierarchical role
*/
final class HierarchicalRole extends Role implements HierarchicalRoleInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe if we use final then add to others also?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, when it's implementing an interface and has no additional public methods, let's mark as final

@DavidHavl
Copy link

Looks great!!

@basz
Copy link
Collaborator Author

basz commented Feb 19, 2018

@svycka thanks. yes, I will do additional changes like php71, remove zf2 support etc... for now could you have a look at the changes from commit e7fd215 and forward?

@svycka
Copy link
Contributor

svycka commented Feb 19, 2018

@svycka thanks. yes, I will do additional changes like php71, remove zf2 support etc... for now could you have a look at the changes from commit e7fd215 and forward?

@basz I already did, but if you could rebase would be a lot easier to review because now it is very hard to see relevant changes.

@basz basz force-pushed the multiple-assertions-develop branch from 29dc027 to 8c3d6a4 Compare February 19, 2018 12:58
@basz
Copy link
Collaborator Author

basz commented Feb 19, 2018

I now figured out what goed wrong. this PR #366 isn't merged into develop yet. Guess I should fix that one first and then rebase this one.

"squizlabs/php_codesniffer": "^2.0",
"doctrine/common": "~2.4"
"malukenho/docheader": "^0.1",
"phpunit/phpunit": "^6.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use v7

use ZfcRbac\Exception;
use ZfcRbac\Identity\IdentityInterface;

class AssertionSet implements AssertionInterface
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's implementing an interface, mark as final

/**
* Simple implementation for a hierarchical role
*/
final class HierarchicalRole extends Role implements HierarchicalRoleInterface
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, when it's implementing an interface and has no additional public methods, let's mark as final

@@ -1,4 +1,6 @@
<?php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there is some git plugin that fixes that, but I forgot the name.

*/
class Permission implements PermissionInterface
class Role implements RoleInterface
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, if it's implementing an interface, mark as final

*/
class AssertionSetTest extends TestCase
{
public function testImplementsAssertionInterface()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we require php 7.1 now? if so, let's add : void

{
return 'role-with-permission-method';
}
public function hasPermission($permission)

public function hasPermission(string $permission): bool
{
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone has a problem when using a MockRole from TestAsset in production, he deserves this problem :)

@prolic
Copy link
Collaborator

prolic commented Feb 20, 2018

Looks good so far, just some minor notes

@prolic prolic mentioned this pull request Feb 20, 2018
@basz basz force-pushed the multiple-assertions-develop branch from 8c3d6a4 to 81178b8 Compare February 20, 2018 16:29
@prolic prolic merged commit c0bf5cb into ZF-Commons:develop Feb 20, 2018
@basz basz deleted the multiple-assertions-develop branch February 22, 2018 11:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants