From ffbebcac458aecb7f695de2685679b9c38186962 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Tue, 9 Aug 2016 12:36:41 +0200 Subject: [PATCH] WIP --- composer.json | 4 +- src/Api/Discovery/BindingDescriptor.php | 33 -- src/Api/Discovery/BindingState.php | 12 +- src/Api/Discovery/BindingTypeDescriptor.php | 24 +- src/Api/Discovery/DiscoveryManager.php | 95 ------ .../Discovery/DuplicateBindingException.php | 42 --- src/Api/Discovery/NoSuchBindingException.php | 61 ---- src/Api/Module/ModuleFile.php | 43 ++- src/Discovery/Binding/AddBinding.php | 6 +- .../AddBindingDescriptorToModuleFile.php | 8 +- .../Binding/BindingDescriptorCollection.php | 101 ++++-- src/Discovery/Binding/DisableBindingUuid.php | 68 ---- src/Discovery/Binding/EnableBindingUuid.php | 68 ---- .../Binding/LoadBindingDescriptor.php | 12 +- .../ReloadBindingDescriptorsByUuid.php | 51 --- .../{SyncBindingUuid.php => SyncBinding.php} | 52 ++-- .../Binding/UnloadBindingDescriptor.php | 9 +- src/Discovery/DiscoveryManagerImpl.php | 274 +--------------- .../Discovery/JsonDiscoveryGenerator.php | 2 +- .../KeyValueStoreDiscoveryGenerator.php | 2 +- tests/Api/Discovery/BindingDescriptorTest.php | 54 +--- .../Discovery/BindingTypeDescriptorTest.php | 24 +- tests/Discovery/DiscoveryManagerImplTest.php | 293 +++++++++--------- 23 files changed, 348 insertions(+), 990 deletions(-) delete mode 100644 src/Api/Discovery/DuplicateBindingException.php delete mode 100644 src/Api/Discovery/NoSuchBindingException.php delete mode 100644 src/Discovery/Binding/DisableBindingUuid.php delete mode 100644 src/Discovery/Binding/EnableBindingUuid.php delete mode 100644 src/Discovery/Binding/ReloadBindingDescriptorsByUuid.php rename src/Discovery/Binding/{SyncBindingUuid.php => SyncBinding.php} (57%) diff --git a/composer.json b/composer.json index a4e2859..ab9878e 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": "^5.3.9|^7.0", - "puli/repository": "^1.0-beta9", - "puli/discovery": "^1.0-beta9", + "puli/repository": "^1.0-beta10@dev", + "puli/discovery": "^1.0-beta10@dev", "puli/url-generator": "^1.0-beta4", "webmozart/json": "^1.3@dev", "webmozart/path-util": "^2.2.3", diff --git a/src/Api/Discovery/BindingDescriptor.php b/src/Api/Discovery/BindingDescriptor.php index 78815b4..f2f02c2 100644 --- a/src/Api/Discovery/BindingDescriptor.php +++ b/src/Api/Discovery/BindingDescriptor.php @@ -130,16 +130,6 @@ public function isLoaded() return null !== $this->state; } - /** - * Returns the UUID of the described binding. - * - * @return Uuid The UUID. - */ - public function getUuid() - { - return $this->binding->getUuid(); - } - /** * Returns the name of the bound type. * @@ -260,27 +250,6 @@ public function isEnabled() return BindingState::ENABLED === $this->state; } - /** - * Returns whether the binding is disabled. - * - * The method {@link load()} needs to be called before calling this method, - * otherwise an exception is thrown. - * - * @return bool Returns `true` if the state is {@link BindingState::DISABLED}. - * - * @throws NotLoadedException If the descriptor is not loaded. - * - * @see BindingState::DISABLED - */ - public function isDisabled() - { - if (null === $this->state) { - throw new NotLoadedException('The binding descriptor is not loaded.'); - } - - return BindingState::DISABLED === $this->state; - } - /** * Returns whether the type of the binding does not exist. * @@ -354,8 +323,6 @@ private function refreshState() $this->state = BindingState::INVALID; } elseif ($this->containingModule instanceof RootModule) { $this->state = BindingState::ENABLED; - } elseif ($this->containingModule->getInstallInfo()->hasDisabledBindingUuid($this->binding->getUuid())) { - $this->state = BindingState::DISABLED; } else { $this->state = BindingState::ENABLED; } diff --git a/src/Api/Discovery/BindingState.php b/src/Api/Discovery/BindingState.php index c5b9a27..fb12460 100644 --- a/src/Api/Discovery/BindingState.php +++ b/src/Api/Discovery/BindingState.php @@ -25,25 +25,20 @@ final class BindingState */ const ENABLED = 1; - /** - * State: The binding is disabled. - */ - const DISABLED = 2; - /** * State: The binding's type does not exist. */ - const TYPE_NOT_FOUND = 3; + const TYPE_NOT_FOUND = 2; /** * State: The binding's type does not exist. */ - const TYPE_NOT_ENABLED = 4; + const TYPE_NOT_ENABLED = 3; /** * State: The binding does not match the constraints of the binding type. */ - const INVALID = 5; + const INVALID = 4; /** * Returns all binding states. @@ -54,7 +49,6 @@ public static function all() { return array( self::ENABLED, - self::DISABLED, self::TYPE_NOT_FOUND, self::TYPE_NOT_ENABLED, self::INVALID, diff --git a/src/Api/Discovery/BindingTypeDescriptor.php b/src/Api/Discovery/BindingTypeDescriptor.php index e0733df..0489eb7 100644 --- a/src/Api/Discovery/BindingTypeDescriptor.php +++ b/src/Api/Discovery/BindingTypeDescriptor.php @@ -48,6 +48,11 @@ class BindingTypeDescriptor */ private $parameterDescriptions = array(); + /** + * @var bool + */ + private $bindingOrderStrict = false; + /** * @var int */ @@ -67,17 +72,22 @@ class BindingTypeDescriptor * @param string[] $parameterDescriptions Human-readable descriptions * indexed by the type's parameter * names. + * @param bool $bindingOrderStrict Whether modules containing the + * bindings of this type must be + * strictly ordered with "depend" + * statements. * * @throws NoSuchParameterException If a description is passed for an unset * parameter. */ - public function __construct(BindingType $type, $description = null, array $parameterDescriptions = array()) + public function __construct(BindingType $type, $description = null, array $parameterDescriptions = array(), $bindingOrderStrict = false) { Assert::nullOrStringNotEmpty($description, 'The description must be a non-empty string or null. Got: %s'); Assert::allStringNotEmpty($parameterDescriptions, 'The parameter description must be a non-empty string. Got: %s'); $this->type = $type; $this->description = $description; + $this->bindingOrderStrict = (bool) $bindingOrderStrict; foreach ($parameterDescriptions as $parameterName => $parameterDescription) { if (!$type->hasParameter($parameterName)) { @@ -245,6 +255,18 @@ public function hasParameterDescriptions() return count($this->parameterDescriptions) > 0; } + /** + * Returns whether the modules containing the bindings of this type must + * be strictly ordered. + * + * @return boolean Returns `true` if the modules must be strictly ordered + * and `false` otherwise. + */ + public function isBindingOrderStrict() + { + return $this->bindingOrderStrict; + } + /** * Returns the module that contains the descriptor. * diff --git a/src/Api/Discovery/DiscoveryManager.php b/src/Api/Discovery/DiscoveryManager.php index 6015c46..90b651c 100644 --- a/src/Api/Discovery/DiscoveryManager.php +++ b/src/Api/Discovery/DiscoveryManager.php @@ -12,8 +12,6 @@ namespace Puli\Manager\Api\Discovery; use Puli\Manager\Api\Context\ProjectContext; -use Puli\Manager\Api\NonRootModuleExpectedException; -use Rhumsaa\Uuid\Uuid; use Webmozart\Expression\Expression; /** @@ -210,16 +208,6 @@ public function hasTypeDescriptors(Expression $expr = null); */ public function addRootBindingDescriptor(BindingDescriptor $bindingDescriptor, $flags = 0); - /** - * Removes a binding from the root module. - * - * The binding descriptor is removed from the root module file. If the - * binding is not found, this method does nothing. - * - * @param Uuid $uuid The UUID of the binding. - */ - public function removeRootBindingDescriptor(Uuid $uuid); - /** * Removes all bindings matching the given expression. * @@ -236,17 +224,6 @@ public function removeRootBindingDescriptors(Expression $expr); */ public function clearRootBindingDescriptors(); - /** - * Returns the binding with the given UUID in the root module. - * - * @param Uuid $uuid The UUID of the binding. - * - * @return BindingDescriptor The binding. - * - * @throws NoSuchBindingException If the binding does not exist. - */ - public function getRootBindingDescriptor(Uuid $uuid); - /** * Returns all bindings in the root module. * @@ -263,17 +240,6 @@ public function getRootBindingDescriptors(); */ public function findRootBindingDescriptors(Expression $expr); - /** - * Returns whether the binding with the given UUID exists in the root - * module. - * - * @param Uuid $uuid The UUID of the binding. - * - * @return bool Returns `true` if the binding exists in the root module and - * `false` otherwise. - */ - public function hasRootBindingDescriptor(Uuid $uuid); - /** * Returns whether the manager has any bindings in the root module. * @@ -289,58 +255,6 @@ public function hasRootBindingDescriptor(Uuid $uuid); */ public function hasRootBindingDescriptors(Expression $expr = null); - /** - * Enables a binding. - * - * @param Uuid $uuid The UUID of the binding. - * - * @throws NoSuchBindingException If the binding does not exist. - * @throws NoSuchTypeException If the type referenced by the descriptor does - * not exist. - * @throws TypeNotEnabledException If the type referenced by the descriptor - * is not enabled. - * @throws NonRootModuleExpectedException If the binding is in the root - * module. Can only enable bindings - * in non-root modules, because the - * bindings in the root module are - * implicitly enabled. - */ - public function enableBindingDescriptor(Uuid $uuid); - - /** - * Disables a binding. - * - * @param Uuid $uuid The UUID of the binding. - * - * @throws NoSuchBindingException If the binding does not exist. - * @throws NoSuchTypeException If the type referenced by the descriptor does - * not exist. - * @throws TypeNotEnabledException If the type referenced by the descriptor - * is not enabled. - * @throws NonRootModuleExpectedException If the binding is in the root - * module. Can only disable bindings - * in non-root modules, because the - * bindings in the root module are - * implicitly enabled. - */ - public function disableBindingDescriptor(Uuid $uuid); - - /** - * Removes disabled binding UUIDs that were not found in any module. - */ - public function removeObsoleteDisabledBindingDescriptors(); - - /** - * Returns the binding with the given UUID. - * - * @param Uuid $uuid The UUID of the binding. - * - * @return BindingDescriptor The binding. - * - * @throws NoSuchBindingException If the binding does not exist. - */ - public function getBindingDescriptor(Uuid $uuid); - /** * Returns all bindings. * @@ -357,15 +271,6 @@ public function getBindingDescriptors(); */ public function findBindingDescriptors(Expression $expr); - /** - * Returns whether the binding with the given UUID exists. - * - * @param Uuid $uuid The UUID of the binding. - * - * @return bool Returns `true` if the binding exists and `false` otherwise. - */ - public function hasBindingDescriptor(Uuid $uuid); - /** * Returns whether the manager has any bindings. * diff --git a/src/Api/Discovery/DuplicateBindingException.php b/src/Api/Discovery/DuplicateBindingException.php deleted file mode 100644 index ae318cd..0000000 --- a/src/Api/Discovery/DuplicateBindingException.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Manager\Api\Discovery; - -use Exception; -use Rhumsaa\Uuid\Uuid; -use RuntimeException; - -/** - * Thrown when a duplicate binding is detected. - * - * @since 1.0 - * - * @author Bernhard Schussek - */ -class DuplicateBindingException extends RuntimeException -{ - /** - * Creates an exception for a duplicate UUID. - * - * @param Uuid $uuid The UUID. - * @param Exception|null $cause The exception that caused this exception. - * - * @return static The created exception. - */ - public static function forUuid(Uuid $uuid, Exception $cause = null) - { - return new static(sprintf( - 'A binding with UUID "%s" exists already.', - $uuid->toString() - ), 0, $cause); - } -} diff --git a/src/Api/Discovery/NoSuchBindingException.php b/src/Api/Discovery/NoSuchBindingException.php deleted file mode 100644 index 3d06247..0000000 --- a/src/Api/Discovery/NoSuchBindingException.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Manager\Api\Discovery; - -use Exception; -use Rhumsaa\Uuid\Uuid; -use RuntimeException; - -/** - * Thrown when a binding was not found. - * - * @since 1.0 - * - * @author Bernhard Schussek - */ -class NoSuchBindingException extends RuntimeException -{ - /** - * Creates an exception for a UUID that was not found. - * - * @param Uuid $uuid The UUID. - * @param Exception|null $cause The exception that caused this exception. - * - * @return static The created exception. - */ - public static function forUuid(Uuid $uuid, Exception $cause = null) - { - return new static(sprintf( - 'The binding with UUID "%s" does not exist.', - $uuid->toString() - ), 0, $cause); - } - - /** - * Creates an exception for a UUID that was not found in a given module. - * - * @param Uuid $uuid The UUID. - * @param string $moduleName The name of the containing module. - * @param Exception|null $cause The exception that caused this - * exception. - * - * @return static The created exception. - */ - public static function forUuidAndModule(Uuid $uuid, $moduleName, Exception $cause = null) - { - return new static(sprintf( - 'The binding with UUID "%s" does not exist in module "%s".', - $uuid->toString(), - $moduleName - ), 0, $cause); - } -} diff --git a/src/Api/Module/ModuleFile.php b/src/Api/Module/ModuleFile.php index e405870..d3c13e9 100644 --- a/src/Api/Module/ModuleFile.php +++ b/src/Api/Module/ModuleFile.php @@ -12,13 +12,13 @@ namespace Puli\Manager\Api\Module; use InvalidArgumentException; +use Puli\Discovery\Api\Binding\Binding; use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Api\Discovery\BindingTypeDescriptor; use Puli\Manager\Api\Discovery\NoSuchBindingException; use Puli\Manager\Api\Repository\NoSuchPathMappingException; use Puli\Manager\Api\Repository\PathMapping; use Puli\Manager\Assert\Assert; -use Rhumsaa\Uuid\Uuid; /** * Stores the configuration of a module. @@ -315,21 +315,21 @@ public function getBindingDescriptors() /** * Returns the binding descriptor with the given UUID. * - * @param Uuid $uuid The UUID of the binding descriptor. + * @param Binding $binding The UUID of the binding descriptor. * * @return BindingDescriptor The binding descriptor. * * @throws NoSuchBindingException If the UUID was not found. */ - public function getBindingDescriptor(Uuid $uuid) + public function getBindingDescriptor(Binding $binding) { - $uuidString = $uuid->toString(); - - if (!isset($this->bindingDescriptors[$uuidString])) { - throw NoSuchBindingException::forUuid($uuid); + foreach ($this->bindingDescriptors as $bindingDescriptor) { + if ($binding->equals($bindingDescriptor->getBinding())) { + return $bindingDescriptor; + } } - return $this->bindingDescriptors[$uuidString]; + throw NoSuchBindingException::forBinding($binding); } /** @@ -339,17 +339,24 @@ public function getBindingDescriptor(Uuid $uuid) */ public function addBindingDescriptor(BindingDescriptor $descriptor) { - $this->bindingDescriptors[$descriptor->getUuid()->toString()] = $descriptor; + // Prevent duplicates + $this->removeBindingDescriptor($descriptor->getBinding()); + + $this->bindingDescriptors[] = $descriptor; } /** * Removes a binding descriptor. * - * @param Uuid $uuid The UUID of the binding descriptor to remove. + * @param Binding $binding The UUID of the binding descriptor to remove. */ - public function removeBindingDescriptor(Uuid $uuid) + public function removeBindingDescriptor(Binding $binding) { - unset($this->bindingDescriptors[$uuid->toString()]); + foreach ($this->bindingDescriptors as $key => $bindingDescriptor) { + if ($binding->equals($bindingDescriptor->getBinding())) { + unset($this->bindingDescriptors[$key]); + } + } } /** @@ -363,13 +370,19 @@ public function clearBindingDescriptors() /** * Returns whether the binding descriptor exists in this file. * - * @param Uuid $uuid The UUID of the binding descriptor. + * @param Binding $binding The UUID of the binding descriptor. * * @return bool Whether the file contains the binding descriptor. */ - public function hasBindingDescriptor(Uuid $uuid) + public function hasBindingDescriptor(Binding $binding) { - return isset($this->bindingDescriptors[$uuid->toString()]); + foreach ($this->bindingDescriptors as $bindingDescriptor) { + if ($binding->equals($bindingDescriptor->getBinding())) { + return true; + } + } + + return false; } /** diff --git a/src/Discovery/Binding/AddBinding.php b/src/Discovery/Binding/AddBinding.php index 77b354b..69cfdd5 100644 --- a/src/Discovery/Binding/AddBinding.php +++ b/src/Discovery/Binding/AddBinding.php @@ -14,6 +14,7 @@ use Puli\Discovery\Api\EditableDiscovery; use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Transaction\AtomicOperation; +use Webmozart\Expression\Expr; /** * Binds a binding descriptor to the resource discovery. @@ -54,6 +55,9 @@ public function execute() */ public function rollback() { - $this->discovery->removeBinding($this->bindingDescriptor->getUuid()); + $this->discovery->removeBindings( + $this->bindingDescriptor->getTypeName(), + Expr::method('equals', $this->bindingDescriptor->getBinding(), Expr::same(true)) + ); } } diff --git a/src/Discovery/Binding/AddBindingDescriptorToModuleFile.php b/src/Discovery/Binding/AddBindingDescriptorToModuleFile.php index 53fe2d1..208b5ca 100644 --- a/src/Discovery/Binding/AddBindingDescriptorToModuleFile.php +++ b/src/Discovery/Binding/AddBindingDescriptorToModuleFile.php @@ -50,10 +50,10 @@ public function __construct(BindingDescriptor $bindingDescriptor, RootModuleFile */ public function execute() { - $uuid = $this->bindingDescriptor->getUuid(); + $binding = $this->bindingDescriptor->getBinding(); - if ($this->rootModuleFile->hasBindingDescriptor($uuid)) { - $this->previousDescriptor = $this->rootModuleFile->getBindingDescriptor($uuid); + if ($this->rootModuleFile->hasBindingDescriptor($binding)) { + $this->previousDescriptor = $this->rootModuleFile->getBindingDescriptor($binding); } $this->rootModuleFile->addBindingDescriptor($this->bindingDescriptor); @@ -67,7 +67,7 @@ public function rollback() if ($this->previousDescriptor) { $this->rootModuleFile->addBindingDescriptor($this->previousDescriptor); } else { - $this->rootModuleFile->removeBindingDescriptor($this->bindingDescriptor->getUuid()); + $this->rootModuleFile->removeBindingDescriptor($this->bindingDescriptor->getBinding()); } } } diff --git a/src/Discovery/Binding/BindingDescriptorCollection.php b/src/Discovery/Binding/BindingDescriptorCollection.php index dfb64af..8ce5299 100644 --- a/src/Discovery/Binding/BindingDescriptorCollection.php +++ b/src/Discovery/Binding/BindingDescriptorCollection.php @@ -12,7 +12,9 @@ namespace Puli\Manager\Discovery\Binding; use OutOfBoundsException; +use Puli\Discovery\Api\Binding\Binding; use Puli\Manager\Api\Discovery\BindingDescriptor; +use Puli\Manager\Util\TwoDimensionalHashMap; use Rhumsaa\Uuid\Uuid; /** @@ -25,17 +27,9 @@ class BindingDescriptorCollection { /** - * @var BindingDescriptor[] + * @var BindingDescriptor[][] */ - private $map; - - /** - * Creates the store. - */ - public function __construct() - { - $this->map = array(); - } + private $map = array(); /** * Adds a binding descriptor. @@ -44,7 +38,11 @@ public function __construct() */ public function add(BindingDescriptor $bindingDescriptor) { - $this->map[$bindingDescriptor->getUuid()->toString()] = $bindingDescriptor; + if ($this->contains($bindingDescriptor->getBinding(), $bindingDescriptor->getContainingModule()->getName())) { + return; + } + + $this->map[$bindingDescriptor->getContainingModule()->getName()][] = $bindingDescriptor; } /** @@ -52,11 +50,22 @@ public function add(BindingDescriptor $bindingDescriptor) * * This method ignores non-existing binding descriptors. * - * @param Uuid $uuid The UUID of the binding descriptor. + * @param Binding $binding The described binding. + * @param string $moduleName The name of the module containing the type. */ - public function remove(Uuid $uuid) + public function remove(Binding $binding, $moduleName) { - unset($this->map[$uuid->toString()]); + if (!isset($this->map[$moduleName])) { + return; + } + + foreach ($this->map[$moduleName] as $key => $bindingDescriptor) { + if ($bindingDescriptor->getBinding()->equals($binding)) { + unset($this->map[$moduleName][$key]); + + break; + } + } } /** @@ -69,16 +78,21 @@ public function remove(Uuid $uuid) * @throws OutOfBoundsException If no binding descriptor was set for the * given UUID. */ - public function get(Uuid $uuid) + public function get(Binding $binding, $moduleName) { - if (!isset($this->map[$uuid->toString()])) { - throw new OutOfBoundsException(sprintf( - 'The binding with UUID "%s" does not exist.', - $uuid->toString() - )); + if (isset($this->map[$moduleName])) { + foreach ($this->map[$moduleName] as $bindingDescriptor) { + if ($bindingDescriptor->getBinding()->equals($binding)) { + return $bindingDescriptor; + } + } } - return $this->map[$uuid->toString()]; + throw new OutOfBoundsException(sprintf( + 'The binding %s in module "%s" does not exist.', + get_class($binding), + $moduleName + )); } /** @@ -89,25 +103,46 @@ public function get(Uuid $uuid) * @return bool Returns `true` if a binding descriptor was set for the given * UUID. */ - public function contains(Uuid $uuid) + public function contains(Binding $binding, $moduleName = null) { - return isset($this->map[$uuid->toString()]); + if (null === $moduleName) { + foreach ($this->map as $bindingDescriptors) { + foreach ($bindingDescriptors as $key => $bindingDescriptor) { + if ($bindingDescriptor->getBinding()->equals($binding)) { + return true; + } + } + } + + return false; + } + + if (!isset($this->map[$moduleName])) { + return false; + } + + foreach ($this->map[$moduleName] as $key => $bindingDescriptor) { + if ($bindingDescriptor->getBinding()->equals($binding)) { + return true; + } + } + + return false; } - /** - * Returns the UUIDs of all binding descriptors. - * - * @return Uuid[] The UUIDs of the stored bindings. - */ - public function getUuids() + public function listByBinding(Binding $binding) { - $uuids = array(); + $bindingDescriptors = array(); - foreach ($this->map as $bindingDescriptor) { - $uuids[] = $bindingDescriptor->getUuid(); + foreach ($this->map as $bindingDescriptors) { + foreach ($bindingDescriptors as $bindingDescriptor) { + if ($bindingDescriptor->getBinding()->equals($binding)) { + $bindingDescriptors[] = $bindingDescriptor; + } + } } - return $uuids; + return $bindingDescriptors; } /** diff --git a/src/Discovery/Binding/DisableBindingUuid.php b/src/Discovery/Binding/DisableBindingUuid.php deleted file mode 100644 index d6ef85b..0000000 --- a/src/Discovery/Binding/DisableBindingUuid.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Manager\Discovery\Binding; - -use Puli\Manager\Api\Module\InstallInfo; -use Puli\Manager\Transaction\AtomicOperation; -use Rhumsaa\Uuid\Uuid; - -/** - * Disables a binding descriptor for a given install info. - * - * @since 1.0 - * - * @author Bernhard Schussek - */ -class DisableBindingUuid implements AtomicOperation -{ - /** - * @var Uuid - */ - private $uuid; - - /** - * @var InstallInfo - */ - private $installInfo; - - /** - * @var bool - */ - private $wasDisabled = true; - - public function __construct(Uuid $uuid, InstallInfo $installInfo) - { - $this->uuid = $uuid; - $this->installInfo = $installInfo; - } - - /** - * {@inheritdoc} - */ - public function execute() - { - if (!$this->installInfo->hasDisabledBindingUuid($this->uuid)) { - $this->wasDisabled = false; - $this->installInfo->addDisabledBindingUuid($this->uuid); - } - } - - /** - * {@inheritdoc} - */ - public function rollback() - { - if (!$this->wasDisabled) { - $this->installInfo->removeDisabledBindingUuid($this->uuid); - } - } -} diff --git a/src/Discovery/Binding/EnableBindingUuid.php b/src/Discovery/Binding/EnableBindingUuid.php deleted file mode 100644 index 73fcb05..0000000 --- a/src/Discovery/Binding/EnableBindingUuid.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Manager\Discovery\Binding; - -use Puli\Manager\Api\Module\InstallInfo; -use Puli\Manager\Transaction\AtomicOperation; -use Rhumsaa\Uuid\Uuid; - -/** - * Enables a binding descriptor for a given install info. - * - * @since 1.0 - * - * @author Bernhard Schussek - */ -class EnableBindingUuid implements AtomicOperation -{ - /** - * @var Uuid - */ - private $uuid; - - /** - * @var InstallInfo - */ - private $installInfo; - - /** - * @var bool - */ - private $wasDisabled = false; - - public function __construct(Uuid $uuid, InstallInfo $installInfo) - { - $this->uuid = $uuid; - $this->installInfo = $installInfo; - } - - /** - * {@inheritdoc} - */ - public function execute() - { - if ($this->installInfo->hasDisabledBindingUuid($this->uuid)) { - $this->wasDisabled = true; - $this->installInfo->removeDisabledBindingUuid($this->uuid); - } - } - - /** - * {@inheritdoc} - */ - public function rollback() - { - if ($this->wasDisabled) { - $this->installInfo->addDisabledBindingUuid($this->uuid); - } - } -} diff --git a/src/Discovery/Binding/LoadBindingDescriptor.php b/src/Discovery/Binding/LoadBindingDescriptor.php index d21d7cb..1f8539a 100644 --- a/src/Discovery/Binding/LoadBindingDescriptor.php +++ b/src/Discovery/Binding/LoadBindingDescriptor.php @@ -75,10 +75,11 @@ public function execute() $this->bindingDescriptor->load($this->containingModule, $typeDescriptor); - $uuid = $this->bindingDescriptor->getUuid(); + $binding = $this->bindingDescriptor->getBinding(); + $moduleName = $this->containingModule->getName(); - if ($this->bindingDescriptors->contains($uuid)) { - $this->previousDescriptor = $this->bindingDescriptors->get($uuid); + if ($this->bindingDescriptors->contains($binding, $moduleName)) { + $this->previousDescriptor = $this->bindingDescriptors->get($binding, $moduleName); } $this->bindingDescriptors->add($this->bindingDescriptor); @@ -102,7 +103,10 @@ public function rollback() $this->bindingDescriptors->add($this->previousDescriptor); } else { // never fails - $this->bindingDescriptors->remove($this->bindingDescriptor->getUuid()); + $this->bindingDescriptors->remove( + $this->bindingDescriptor->getBinding(), + $this->bindingDescriptor->getContainingModule()->getName() + ); } } } diff --git a/src/Discovery/Binding/ReloadBindingDescriptorsByUuid.php b/src/Discovery/Binding/ReloadBindingDescriptorsByUuid.php deleted file mode 100644 index 86e5c68..0000000 --- a/src/Discovery/Binding/ReloadBindingDescriptorsByUuid.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Manager\Discovery\Binding; - -use Puli\Manager\Discovery\Type\BindingTypeDescriptorCollection; -use Rhumsaa\Uuid\Uuid; - -/** - * Reloads all binding descriptors with a given UUID. - * - * @since 1.0 - * - * @author Bernhard Schussek - */ -class ReloadBindingDescriptorsByUuid extends AbstractReloadBindingDescriptors -{ - /** - * @var Uuid - */ - private $uuid; - - /** - * @var BindingDescriptorCollection - */ - private $bindingDescriptors; - - public function __construct(Uuid $uuid, BindingDescriptorCollection $bindingDescriptors, BindingTypeDescriptorCollection $typeDescriptors) - { - parent::__construct($typeDescriptors); - - $this->uuid = $uuid; - $this->bindingDescriptors = $bindingDescriptors; - } - - /** - * {@inheritdoc} - */ - public function postExecute() - { - $this->reloadBindingDescriptor($this->bindingDescriptors->get($this->uuid)); - } -} diff --git a/src/Discovery/Binding/SyncBindingUuid.php b/src/Discovery/Binding/SyncBinding.php similarity index 57% rename from src/Discovery/Binding/SyncBindingUuid.php rename to src/Discovery/Binding/SyncBinding.php index 318926c..3807db3 100644 --- a/src/Discovery/Binding/SyncBindingUuid.php +++ b/src/Discovery/Binding/SyncBinding.php @@ -12,32 +12,34 @@ namespace Puli\Manager\Discovery\Binding; use LogicException; +use Puli\Discovery\Api\Binding\Binding; use Puli\Discovery\Api\EditableDiscovery; use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Transaction\AtomicOperation; use Rhumsaa\Uuid\Uuid; +use Webmozart\Expression\Expr; /** - * Synchronizes a binding descriptor UUID with the discovery. + * Synchronizes a binding descriptor with the discovery. * * The method {@link takeSnapshot()} must be called before executing the - * operation. This method will record whether a binding descriptor is currently - * enabled (i.e. loaded in the discovery) for that UUID. + * operation. This method will record whether the binding descriptor is currently + * enabled (i.e. loaded in the discovery). * * Once the operation is executed, another snapshot is taken. If the snapshots - * differ, the binding descriptor for the UUID is then either bound to or - * unbound from the discovery, depending on the outcome. + * differ, the binding descriptor is then either added to or removed from the + * discovery, depending on the outcome. * * @since 1.0 * * @author Bernhard Schussek */ -class SyncBindingUuid implements AtomicOperation +class SyncBinding implements AtomicOperation { /** - * @var Uuid + * @var Binding */ - private $uuid; + private $binding; /** * @var EditableDiscovery @@ -64,9 +66,9 @@ class SyncBindingUuid implements AtomicOperation */ private $snapshotTaken = false; - public function __construct(Uuid $uuid, EditableDiscovery $discovery, BindingDescriptorCollection $bindingDescriptors) + public function __construct(Binding $binding, EditableDiscovery $discovery, BindingDescriptorCollection $bindingDescriptors) { - $this->uuid = $uuid; + $this->binding = $binding; $this->discovery = $discovery; $this->bindingDescriptors = $bindingDescriptors; } @@ -78,9 +80,7 @@ public function takeSnapshot() { $this->enabledBindingBefore = null; - if ($this->bindingDescriptors->contains($this->uuid)) { - $bindingDescriptor = $this->bindingDescriptors->get($this->uuid); - + foreach ($this->bindingDescriptors->listByBinding($this->binding) as $bindingDescriptor) { if ($bindingDescriptor->isEnabled()) { // Clone so that rollback() works if the binding is unloaded $this->enabledBindingBefore = clone $bindingDescriptor; @@ -102,16 +102,14 @@ public function execute() // Remember for rollback() $this->enabledBindingAfter = null; - if ($this->bindingDescriptors->contains($this->uuid)) { - $bindingDescriptor = $this->bindingDescriptors->get($this->uuid); - + foreach ($this->bindingDescriptors->listByBinding($this->binding) as $bindingDescriptor) { if ($bindingDescriptor->isEnabled()) { // Clone so that rollback() works if the binding is unloaded $this->enabledBindingAfter = clone $bindingDescriptor; } } - $this->syncBindingUuid($this->enabledBindingBefore, $this->enabledBindingAfter); + $this->syncBinding($this->enabledBindingBefore, $this->enabledBindingAfter); } /** @@ -119,18 +117,24 @@ public function execute() */ public function rollback() { - $this->syncBindingUuid($this->enabledBindingAfter, $this->enabledBindingBefore); + $this->syncBinding($this->enabledBindingAfter, $this->enabledBindingBefore); } - private function syncBindingUuid(BindingDescriptor $enabledBefore = null, BindingDescriptor $enabledAfter = null) + private function syncBinding(BindingDescriptor $enabledBefore = null, BindingDescriptor $enabledAfter = null) { if (!$enabledBefore && $enabledAfter) { - $this->discovery->addBinding($enabledAfter->getBinding()); + $this->discovery->addBinding($this->binding); } elseif ($enabledBefore && !$enabledAfter) { - $this->discovery->removeBinding($enabledBefore->getUuid()); - } elseif ($enabledBefore && $enabledAfter && $enabledBefore->getBinding() != $enabledAfter->getBinding()) { - $this->discovery->removeBinding($enabledBefore->getUuid()); - $this->discovery->addBinding($enabledAfter->getBinding()); + $this->discovery->removeBindings( + $this->binding->getTypeName(), + Expr::method('equals', $this->binding, Expr::same(true)) + ); +// } elseif ($enabledBefore && $enabledAfter && !$enabledBefore->getBinding()->equals($enabledAfter->getBinding())) { +// $this->discovery->removeBindings( +// $enabledBefore->getTypeName(), +// Expr::method('equals', $enabledBefore->getBinding(), Expr::same(true)) +// ); +// $this->discovery->addBinding($enabledAfter->getBinding()); } } } diff --git a/src/Discovery/Binding/UnloadBindingDescriptor.php b/src/Discovery/Binding/UnloadBindingDescriptor.php index 60134b7..bfad791 100644 --- a/src/Discovery/Binding/UnloadBindingDescriptor.php +++ b/src/Discovery/Binding/UnloadBindingDescriptor.php @@ -69,15 +69,16 @@ public function execute() $this->containingModule = $this->bindingDescriptor->getContainingModule(); $this->typeDescriptor = $this->bindingDescriptor->getTypeDescriptor(); - $uuid = $this->bindingDescriptor->getUuid(); + $binding = $this->bindingDescriptor->getBinding(); + $moduleName = $this->containingModule->getName(); // never fails with the check in the beginning $this->bindingDescriptor->unload(); - if ($this->bindingDescriptors->contains($uuid) - && $this->bindingDescriptor === $this->bindingDescriptors->get($uuid)) { + if ($this->bindingDescriptors->contains($binding, $moduleName) + && $this->bindingDescriptor === $this->bindingDescriptors->get($binding, $moduleName)) { // never fails - $this->bindingDescriptors->remove($uuid); + $this->bindingDescriptors->remove($binding, $moduleName); $this->wasRemoved = true; } } diff --git a/src/Discovery/DiscoveryManagerImpl.php b/src/Discovery/DiscoveryManagerImpl.php index 2851c7b..718b636 100644 --- a/src/Discovery/DiscoveryManagerImpl.php +++ b/src/Discovery/DiscoveryManagerImpl.php @@ -14,6 +14,7 @@ use Exception; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Puli\Discovery\Api\Binding\Binding; use Puli\Discovery\Api\EditableDiscovery; use Puli\Manager\Api\Context\ProjectContext; use Puli\Manager\Api\Discovery\BindingDescriptor; @@ -39,9 +40,8 @@ use Puli\Manager\Discovery\Binding\EnableBindingUuid; use Puli\Manager\Discovery\Binding\LoadBindingDescriptor; use Puli\Manager\Discovery\Binding\ReloadBindingDescriptorsByTypeName; -use Puli\Manager\Discovery\Binding\ReloadBindingDescriptorsByUuid; use Puli\Manager\Discovery\Binding\RemoveBindingDescriptorFromModuleFile; -use Puli\Manager\Discovery\Binding\SyncBindingUuid; +use Puli\Manager\Discovery\Binding\SyncBinding; use Puli\Manager\Discovery\Binding\UnloadBindingDescriptor; use Puli\Manager\Discovery\Type\AddBindingType; use Puli\Manager\Discovery\Type\AddTypeDescriptorToModuleFile; @@ -165,7 +165,7 @@ public function addRootTypeDescriptor(BindingTypeDescriptor $typeDescriptor, $fl $syncBindingOps = array(); foreach ($this->getUuidsByTypeName($typeName) as $uuid) { - $syncBindingOp = $this->syncBindingUuid($uuid); + $syncBindingOp = $this->syncBinding($uuid); $syncBindingOp->takeSnapshot(); $syncBindingOps[] = $syncBindingOp; } @@ -215,7 +215,7 @@ public function removeRootTypeDescriptor($typeName) $syncBindingOps = array(); foreach ($this->getUuidsByTypeName($typeName) as $uuid) { - $syncBindingOp = $this->syncBindingUuid($uuid); + $syncBindingOp = $this->syncBinding($uuid); $syncBindingOp->takeSnapshot(); $syncBindingOps[] = $syncBindingOp; } @@ -260,7 +260,7 @@ public function removeRootTypeDescriptors(Expression $expr) $tx->execute($this->removeTypeDescriptorFromModuleFile($typeName)); foreach ($this->getUuidsByTypeName($typeName) as $uuid) { - $syncBindingOp = $this->syncBindingUuid($uuid); + $syncBindingOp = $this->syncBinding($uuid); $syncBindingOp->takeSnapshot(); $syncBindingOps[] = $syncBindingOp; } @@ -464,21 +464,21 @@ public function addRootBindingDescriptor(BindingDescriptor $bindingDescriptor, $ throw TypeNotEnabledException::forTypeName($typeName); } - $uuid = $bindingDescriptor->getUuid(); - $exists = $this->bindingDescriptors->contains($uuid); + $binding = $bindingDescriptor->getBinding(); + $exists = $this->bindingDescriptors->contains($binding); $existsInNonRoot = $exists - ? !($this->bindingDescriptors->get($uuid)->getContainingModule() instanceof RootModule) + ? !$this->bindingDescriptors->contains($binding, $this->rootModule->getName()) : false; // We can only override bindings in the root module if ($existsInNonRoot || ($exists && !($flags & self::OVERRIDE))) { - throw DuplicateBindingException::forUuid($uuid); + throw DuplicateBindingException::forUuid($binding); } $tx = new Transaction(); try { - $syncOp = $this->syncBindingUuid($uuid); + $syncOp = $this->syncBinding($binding); $syncOp->takeSnapshot(); $tx->execute($this->loadBindingDescriptor($bindingDescriptor, $this->rootModule)); @@ -498,43 +498,6 @@ public function addRootBindingDescriptor(BindingDescriptor $bindingDescriptor, $ } } - /** - * {@inheritdoc} - */ - public function removeRootBindingDescriptor(Uuid $uuid) - { - $this->assertModulesLoaded(); - - if (!$this->bindingDescriptors->contains($uuid)) { - return; - } - - $bindingDescriptor = $this->bindingDescriptors->get($uuid); - - if (!$bindingDescriptor->getContainingModule() instanceof RootModule) { - return; - } - - $tx = new Transaction(); - - try { - $syncOp = $this->syncBindingUuid($uuid); - $syncOp->takeSnapshot(); - - $tx->execute($this->unloadBindingDescriptor($bindingDescriptor)); - $tx->execute($syncOp); - $tx->execute($this->removeBindingDescriptorFromModuleFile($uuid)); - - $this->saveRootModuleFile(); - - $tx->commit(); - } catch (Exception $e) { - $tx->rollback(); - - throw $e; - } - } - /** * {@inheritdoc} */ @@ -547,7 +510,7 @@ public function removeRootBindingDescriptors(Expression $expr) try { foreach ($this->getRootBindingDescriptors() as $bindingDescriptor) { if ($expr->evaluate($bindingDescriptor)) { - $syncOp = $this->syncBindingUuid($bindingDescriptor->getUuid()); + $syncOp = $this->syncBinding($bindingDescriptor->getUuid()); $syncOp->takeSnapshot(); $tx->execute($this->unloadBindingDescriptor($bindingDescriptor)); @@ -574,20 +537,6 @@ public function clearRootBindingDescriptors() $this->removeRootBindingDescriptors(Expr::true()); } - /** - * {@inheritdoc} - */ - public function getRootBindingDescriptor(Uuid $uuid) - { - $binding = $this->getBindingDescriptor($uuid); - - if (!$binding->getContainingModule() instanceof RootModule) { - throw NoSuchBindingException::forUuidAndModule($uuid, $this->rootModule->getName()); - } - - return $binding; - } - /** * {@inheritdoc} */ @@ -617,14 +566,6 @@ public function findRootBindingDescriptors(Expression $expr) return $this->findBindingDescriptors($expr); } - /** - * {@inheritdoc} - */ - public function hasRootBindingDescriptor(Uuid $uuid) - { - return $this->hasBindingDescriptor($uuid) && $this->getBindingDescriptor($uuid)->getContainingModule() instanceof RootModule; - } - /** * {@inheritdoc} */ @@ -639,151 +580,6 @@ public function hasRootBindingDescriptors(Expression $expr = null) return $this->hasBindingDescriptors($expr2); } - /** - * {@inheritdoc} - */ - public function enableBindingDescriptor(Uuid $uuid) - { - $this->assertModulesLoaded(); - - if (!$this->bindingDescriptors->contains($uuid)) { - throw NoSuchBindingException::forUuid($uuid); - } - - $bindingDescriptor = $this->bindingDescriptors->get($uuid); - $module = $bindingDescriptor->getContainingModule(); - - if ($module instanceof RootModule) { - throw NonRootModuleExpectedException::cannotEnableBinding($uuid, $module->getName()); - } - - if ($bindingDescriptor->isTypeNotFound()) { - throw NoSuchTypeException::forTypeName($bindingDescriptor->getTypeName()); - } - - if ($bindingDescriptor->isTypeNotEnabled()) { - throw TypeNotEnabledException::forTypeName($bindingDescriptor->getTypeName()); - } - - if ($bindingDescriptor->isEnabled()) { - return; - } - - $tx = new Transaction(); - - try { - $syncOp = $this->syncBindingUuid($uuid); - $syncOp->takeSnapshot(); - - $tx->execute($this->enableBindingUuid($uuid, $module->getInstallInfo())); - $tx->execute($syncOp); - - $this->saveRootModuleFile(); - - $tx->commit(); - } catch (Exception $e) { - $tx->rollback(); - - throw $e; - } - } - - /** - * {@inheritdoc} - */ - public function disableBindingDescriptor(Uuid $uuid) - { - $this->assertModulesLoaded(); - - if (!$this->bindingDescriptors->contains($uuid)) { - throw NoSuchBindingException::forUuid($uuid); - } - - $bindingDescriptor = $this->bindingDescriptors->get($uuid); - $module = $bindingDescriptor->getContainingModule(); - - if ($module instanceof RootModule) { - throw NonRootModuleExpectedException::cannotDisableBinding($uuid, $module->getName()); - } - - if ($bindingDescriptor->isTypeNotFound()) { - throw NoSuchTypeException::forTypeName($bindingDescriptor->getTypeName()); - } - - if ($bindingDescriptor->isTypeNotEnabled()) { - throw TypeNotEnabledException::forTypeName($bindingDescriptor->getTypeName()); - } - - if ($bindingDescriptor->isDisabled()) { - return; - } - - $tx = new Transaction(); - - try { - $syncOp = $this->syncBindingUuid($uuid); - $syncOp->takeSnapshot(); - - $tx->execute($this->disableBindingUuid($uuid, $module->getInstallInfo())); - $tx->execute($syncOp); - - $this->saveRootModuleFile(); - - $tx->commit(); - } catch (Exception $e) { - $tx->rollback(); - - throw $e; - } - } - - /** - * {@inheritdoc} - */ - public function removeObsoleteDisabledBindingDescriptors() - { - $this->assertModulesLoaded(); - - $removedUuidsByModule = array(); - - try { - foreach ($this->rootModuleFile->getInstallInfos() as $installInfo) { - foreach ($installInfo->getDisabledBindingUuids() as $uuid) { - if (!$this->bindingDescriptors->contains($uuid)) { - $installInfo->removeDisabledBindingUuid($uuid); - $removedUuidsByModule[$installInfo->getModuleName()][] = $uuid; - } - } - } - - $this->saveRootModuleFile(); - } catch (Exception $e) { - foreach ($removedUuidsByModule as $moduleName => $removedUuids) { - $installInfo = $this->rootModuleFile->getInstallInfo($moduleName); - - foreach ($removedUuids as $uuid) { - $installInfo->addDisabledBindingUuid($uuid); - } - } - - throw $e; - } - } - - /** - * {@inheritdoc} - */ - public function getBindingDescriptor(Uuid $uuid) - { - $this->assertModulesLoaded(); - - if (!$this->bindingDescriptors->contains($uuid)) { - throw NoSuchBindingException::forUuid($uuid); - } - - return $this->bindingDescriptors->get($uuid); - } - /** * {@inheritdoc} */ @@ -812,16 +608,6 @@ public function findBindingDescriptors(Expression $expr) return $descriptors; } - /** - * {@inheritdoc} - */ - public function hasBindingDescriptor(Uuid $uuid) - { - $this->assertModulesLoaded(); - - return $this->bindingDescriptors->contains($uuid); - } - /** * {@inheritdoc} */ @@ -929,11 +715,6 @@ private function loadModules() } foreach ($module->getModuleFile()->getBindingDescriptors() as $bindingDescriptor) { - // This REALLY shouldn't happen - if ($this->bindingDescriptors->contains($bindingDescriptor->getUuid())) { - throw DuplicateBindingException::forUuid($bindingDescriptor->getUuid()); - } - $this->loadBindingDescriptor($bindingDescriptor, $module)->execute(); } } @@ -972,19 +753,6 @@ private function emitWarningForInvalidBindings() } } - private function getUuidsByTypeName($typeName) - { - $uuids = array(); - - foreach ($this->bindingDescriptors->getUuids() as $uuid) { - if ($typeName === $this->bindingDescriptors->get($uuid)->getTypeName()) { - $uuids[$uuid->toString()] = $uuid; - } - } - - return $uuids; - } - private function saveRootModuleFile() { $this->jsonStorage->saveRootModuleFile($this->rootModuleFile); @@ -1056,29 +824,13 @@ private function unloadBindingDescriptor(BindingDescriptor $bindingDescriptor) return new UnloadBindingDescriptor($bindingDescriptor, $this->bindingDescriptors); } - private function enableBindingUuid(Uuid $uuid, InstallInfo $installInfo) - { - return new InterceptedOperation( - new EnableBindingUuid($uuid, $installInfo), - new ReloadBindingDescriptorsByUuid($uuid, $this->bindingDescriptors, $this->typeDescriptors) - ); - } - - private function disableBindingUuid(Uuid $uuid, InstallInfo $installInfo) - { - return new InterceptedOperation( - new DisableBindingUuid($uuid, $installInfo), - new ReloadBindingDescriptorsByUuid($uuid, $this->bindingDescriptors, $this->typeDescriptors) - ); - } - private function addBinding(BindingDescriptor $bindingDescriptor) { return new AddBinding($bindingDescriptor, $this->discovery); } - private function syncBindingUuid(Uuid $uuid) + private function syncBinding(Binding $binding) { - return new SyncBindingUuid($uuid, $this->discovery, $this->bindingDescriptors); + return new SyncBinding($binding, $this->discovery, $this->bindingDescriptors); } } diff --git a/src/Factory/Generator/Discovery/JsonDiscoveryGenerator.php b/src/Factory/Generator/Discovery/JsonDiscoveryGenerator.php index 9ebaf85..976af17 100644 --- a/src/Factory/Generator/Discovery/JsonDiscoveryGenerator.php +++ b/src/Factory/Generator/Discovery/JsonDiscoveryGenerator.php @@ -47,7 +47,7 @@ public function generateNewInstance($varName, Method $targetMethod, GeneratorReg $escPath = '__DIR__.'.var_export('/'.$relPath, true); $targetMethod->getClass()->addImport(new Import('Puli\Discovery\JsonDiscovery')); - $targetMethod->getClass()->addImport(new Import('Puli\Discovery\Binding\Initializer\ResourceBindingInitializer')); + $targetMethod->getClass()->addImport(new Import('Puli\Repository\Discovery\ResourceBindingInitializer')); $targetMethod->addBody(sprintf( "$%s = new JsonDiscovery(%s, array(\n new ResourceBindingInitializer(\$repo),\n));", diff --git a/src/Factory/Generator/Discovery/KeyValueStoreDiscoveryGenerator.php b/src/Factory/Generator/Discovery/KeyValueStoreDiscoveryGenerator.php index 5318c83..0b60999 100644 --- a/src/Factory/Generator/Discovery/KeyValueStoreDiscoveryGenerator.php +++ b/src/Factory/Generator/Discovery/KeyValueStoreDiscoveryGenerator.php @@ -54,7 +54,7 @@ public function generateNewInstance($varName, Method $targetMethod, GeneratorReg $kvsGenerator->generateNewInstance('store', $targetMethod, $generatorRegistry, $kvsOptions); $targetMethod->getClass()->addImport(new Import('Puli\Discovery\KeyValueStoreDiscovery')); - $targetMethod->getClass()->addImport(new Import('Puli\Discovery\Binding\Initializer\ResourceBindingInitializer')); + $targetMethod->getClass()->addImport(new Import('Puli\Repository\Discovery\ResourceBindingInitializer')); $targetMethod->addBody(sprintf( "$%s = new KeyValueStoreDiscovery(\$store, array(\n new ResourceBindingInitializer(\$repo),\n));", diff --git a/tests/Api/Discovery/BindingDescriptorTest.php b/tests/Api/Discovery/BindingDescriptorTest.php index ee835e6..0a26c30 100644 --- a/tests/Api/Discovery/BindingDescriptorTest.php +++ b/tests/Api/Discovery/BindingDescriptorTest.php @@ -33,7 +33,7 @@ */ class BindingDescriptorTest extends PHPUnit_Framework_TestCase { - private $uuid; + const CLASS_BINDING = 'Puli\Discovery\Binding\ClassBinding'; /** * @var Module @@ -47,7 +47,6 @@ class BindingDescriptorTest extends PHPUnit_Framework_TestCase protected function setUp() { - $this->uuid = Uuid::uuid4(); $this->module = new Module(new ModuleFile(), '/path', new InstallInfo('vendor/module', '/path')); $this->rootModule = new RootModule(new RootModuleFile(), '/root'); } @@ -62,7 +61,7 @@ public function testCreate() public function testLoadInitializesBinding() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('foo', BindingParameter::OPTIONAL, 'bar'), new BindingParameter('param', BindingParameter::OPTIONAL, 'default'), )); @@ -90,7 +89,7 @@ public function testTypeNotFoundIfTypeIsNull() public function testTypeNotFoundIfTypeIsNotLoaded() { - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::CLASS_BINDING); $typeDescriptor = new BindingTypeDescriptor($type); $binding = new ClassBinding(__CLASS__, Foo::clazz); @@ -102,7 +101,7 @@ public function testTypeNotFoundIfTypeIsNotLoaded() public function testTypeNotEnabledIfTypeIsNotEnabled() { - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::CLASS_BINDING); $typeDescriptor = new BindingTypeDescriptor($type); $typeDescriptor->load($this->module); $typeDescriptor->markDuplicate(true); @@ -116,7 +115,7 @@ public function testTypeNotEnabledIfTypeIsNotEnabled() public function testInvalidIfInvalidParameter() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param', BindingParameter::REQUIRED), )); $typeDescriptor = new BindingTypeDescriptor($type); @@ -133,7 +132,7 @@ public function testInvalidIfInvalidParameter() public function testParametersNotValidatedIfTypeNotEnabled() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param', BindingParameter::REQUIRED), )); $typeDescriptor = new BindingTypeDescriptor($type); @@ -148,45 +147,4 @@ public function testParametersNotValidatedIfTypeNotEnabled() $this->assertSame(BindingState::TYPE_NOT_ENABLED, $descriptor->getState()); $this->assertCount(0, $descriptor->getLoadErrors()); } - - public function testEnabledInRootModule() - { - $type = new BindingType(Foo::clazz); - $typeDescriptor = new BindingTypeDescriptor($type); - $typeDescriptor->load($this->module); - - $binding = new ClassBinding(__CLASS__, Foo::clazz); - $descriptor = new BindingDescriptor($binding); - $descriptor->load($this->rootModule, $typeDescriptor); - - $this->assertSame(BindingState::ENABLED, $descriptor->getState()); - } - - public function testDisabledIfDisabled() - { - $type = new BindingType(Foo::clazz); - $typeDescriptor = new BindingTypeDescriptor($type); - $typeDescriptor->load($this->module); - - $this->module->getInstallInfo()->addDisabledBindingUuid($this->uuid); - - $binding = new ClassBinding(__CLASS__, Foo::clazz, array(), $this->uuid); - $descriptor = new BindingDescriptor($binding); - $descriptor->load($this->module, $typeDescriptor); - - $this->assertSame(BindingState::DISABLED, $descriptor->getState()); - } - - public function testEnabledIfNotDisabled() - { - $type = new BindingType(Foo::clazz); - $typeDescriptor = new BindingTypeDescriptor($type); - $typeDescriptor->load($this->module); - - $binding = new ClassBinding(__CLASS__, Foo::clazz); - $descriptor = new BindingDescriptor($binding); - $descriptor->load($this->module, $typeDescriptor); - - $this->assertSame(BindingState::ENABLED, $descriptor->getState()); - } } diff --git a/tests/Api/Discovery/BindingTypeDescriptorTest.php b/tests/Api/Discovery/BindingTypeDescriptorTest.php index 60b29c7..a0a5eb0 100644 --- a/tests/Api/Discovery/BindingTypeDescriptorTest.php +++ b/tests/Api/Discovery/BindingTypeDescriptorTest.php @@ -28,6 +28,8 @@ */ class BindingTypeDescriptorTest extends PHPUnit_Framework_TestCase { + const CLASS_BINDING = 'Puli\Discovery\Binding\ClassBinding'; + /** * @var Module */ @@ -40,7 +42,7 @@ protected function setUp() public function testCreate() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param'), )); @@ -56,7 +58,7 @@ public function testCreate() public function testCreateWithParameterDescription() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param'), )); @@ -75,7 +77,7 @@ public function testCreateWithParameterDescription() */ public function testDescriptionMustBeStringOrNull() { - new BindingTypeDescriptor(new BindingType(Foo::clazz), 1234); + new BindingTypeDescriptor(new BindingType(Foo::clazz, self::CLASS_BINDING), 1234); } /** @@ -83,7 +85,7 @@ public function testDescriptionMustBeStringOrNull() */ public function testDescriptionMustNotBeEmpty() { - new BindingTypeDescriptor(new BindingType(Foo::clazz), ''); + new BindingTypeDescriptor(new BindingType(Foo::clazz, self::CLASS_BINDING), ''); } /** @@ -91,7 +93,7 @@ public function testDescriptionMustNotBeEmpty() */ public function testParameterDescriptionsMustBeStringOrNull() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param'), )); @@ -103,7 +105,7 @@ public function testParameterDescriptionsMustBeStringOrNull() */ public function testParameterDescriptionsMustNotBeEmpty() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param'), )); @@ -116,7 +118,7 @@ public function testParameterDescriptionsMustNotBeEmpty() */ public function testCreateFailsIfInvalidParameter() { - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::CLASS_BINDING); new BindingTypeDescriptor($type, null, array('foo' => 'The parameter description.')); } @@ -126,7 +128,7 @@ public function testCreateFailsIfInvalidParameter() */ public function testGetParameterDescriptionFailsIfUnknownParameter() { - $descriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz)); + $descriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz, self::CLASS_BINDING)); $descriptor->getParameterDescription('foobar'); } @@ -136,7 +138,7 @@ public function testGetParameterDescriptionFailsIfUnknownParameter() */ public function testGetParameterDescriptionFailsIfUndescribedParameter() { - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::CLASS_BINDING, array( new BindingParameter('param'), )); @@ -147,7 +149,7 @@ public function testGetParameterDescriptionFailsIfUndescribedParameter() public function testEnabledIfLoaded() { - $descriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz)); + $descriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz, self::CLASS_BINDING)); $descriptor->load($this->module); $this->assertSame(BindingTypeState::ENABLED, $descriptor->getState()); @@ -155,7 +157,7 @@ public function testEnabledIfLoaded() public function testDuplicateIfMarkedDuplicate() { - $descriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz)); + $descriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz, self::CLASS_BINDING)); $descriptor->load($this->module); $descriptor->markDuplicate(true); diff --git a/tests/Discovery/DiscoveryManagerImplTest.php b/tests/Discovery/DiscoveryManagerImplTest.php index 6c7cf34..9afdcae 100644 --- a/tests/Discovery/DiscoveryManagerImplTest.php +++ b/tests/Discovery/DiscoveryManagerImplTest.php @@ -16,7 +16,6 @@ use Psr\Log\LoggerInterface; use Puli\Discovery\Api\Type\BindingParameter; use Puli\Discovery\Api\Type\BindingType; -use Puli\Discovery\Binding\ResourceBinding; use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Api\Discovery\BindingTypeDescriptor; use Puli\Manager\Api\Discovery\DiscoveryManager; @@ -33,6 +32,7 @@ use Puli\Manager\Tests\Discovery\Fixtures\Foo; use Puli\Manager\Tests\ManagerTestCase; use Puli\Manager\Tests\TestException; +use Puli\Repository\Discovery\ResourceBinding; use Rhumsaa\Uuid\Uuid; use Symfony\Component\Filesystem\Filesystem; use Webmozart\Expression\Expr; @@ -47,6 +47,8 @@ class DiscoveryManagerImplTest extends ManagerTestCase { const NOT_FOUND_UUID = 'fa1a334b-35ba-4662-ab5e-d64394f3081e'; + const RESOURCE_BINDING = 'Puli\Repository\Discovery\ResourceBinding'; + /** * @var string */ @@ -153,21 +155,6 @@ protected function tearDown() $filesystem->remove($this->tempDir); } - /** - * @expectedException \Puli\Manager\Api\Discovery\DuplicateBindingException - */ - public function testLoadFailsIfDuplicateUuid() - { - $this->initDefaultManager(); - - $binding = new ResourceBinding('/path', Foo::clazz); - - $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($binding)); - $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); - - $this->manager->getBindingDescriptors(); - } - public function testLoadIgnoresModulesWithoutModuleFile() { $this->rootModuleFile->addInstallInfo($this->installInfo1); @@ -185,7 +172,7 @@ public function testAddRootTypeDescriptor() { $this->initDefaultManager(); - $typeDescriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz)); + $typeDescriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING)); $this->discovery->expects($this->once()) ->method('addBindingType') @@ -212,7 +199,7 @@ public function testAddRootTypeDescriptorFailsIfAlreadyDefined() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->moduleFile1->addTypeDescriptor($typeDescriptor = new BindingTypeDescriptor($type)); @@ -227,11 +214,11 @@ public function testAddRootTypeDescriptorFailsIfAlreadyDefined() $this->assertFalse($typeDescriptor->isEnabled()); } - public function testAddRootTypeDescriptorDoesNotFailIfAlreadyDefinedAndNoDuplicateCheck() + public function testAddRootTypeDescriptorDoesNotFailIfAlreadyDefinedAndOverride() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $typeDescriptor1 = new BindingTypeDescriptor($type); $typeDescriptor2 = clone $typeDescriptor1; @@ -264,7 +251,7 @@ public function testAddRootTypeDescriptorAddsBindingsWithTypeNotLoaded() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding = new ResourceBinding('/path', Foo::clazz); $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($binding)); @@ -295,11 +282,11 @@ public function testAddRootTypeDescriptorUndefinesTypeIfSavingFails() { $this->initDefaultManager(); - $existingDescriptor = new BindingTypeDescriptor(new BindingType(Bar::clazz)); + $existingDescriptor = new BindingTypeDescriptor(new BindingType(Bar::clazz, self::RESOURCE_BINDING)); $this->rootModuleFile->addTypeDescriptor($existingDescriptor); - $typeDescriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz)); + $typeDescriptor = new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING)); $this->discovery->expects($this->once()) ->method('addBindingType') @@ -330,7 +317,7 @@ public function testRemoveRootTypeDescriptor() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor = new BindingTypeDescriptor($type)); @@ -369,7 +356,7 @@ public function testRemoveRootTypeDescriptorIgnoresIfNotInRootModule() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->moduleFile1->addTypeDescriptor($typeDescriptor = new BindingTypeDescriptor($type)); @@ -388,7 +375,7 @@ public function testRemoveRootTypeDescriptorDefinesTypeIfResolvingDuplication() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = clone $typeDescriptor1); @@ -419,7 +406,7 @@ public function testRemoveRootTypeDescriptorDoesNotDefineTypeIfStillDuplicated() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = clone $typeDescriptor1); @@ -451,7 +438,7 @@ public function testRemoveRootTypeDescriptorUnbindsCorrespondingBindings() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding = new ResourceBinding('/path', Foo::clazz); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type)); @@ -462,8 +449,8 @@ public function testRemoveRootTypeDescriptorUnbindsCorrespondingBindings() ->with(Foo::clazz); $this->discovery->expects($this->once()) - ->method('removeBinding') - ->with($binding->getUuid()); + ->method('removeBindings') + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -481,7 +468,7 @@ public function testRemoveRootTypeDescriptorAddsFormerlyIgnoredBindings() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding = new ResourceBinding('/path', Foo::clazz); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type)); @@ -515,7 +502,7 @@ public function testRemoveRootTypeDescriptorDoesNotAddFormerlyIgnoredBindingsIfS { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding = new ResourceBinding('/path', Foo::clazz); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type)); @@ -548,7 +535,7 @@ public function testRemoveRootTypeDescriptorDoesNotEmitWarningForRemovedDuplicat { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = clone $typeDescriptor1); @@ -580,9 +567,9 @@ public function testRemoveRootTypeDescriptorEmitsWarningIfDuplicatedMoreThanOnce { $this->initDefaultManager(); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile2->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile2->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->logger->expects($this->once()) ->method('warning'); @@ -609,7 +596,7 @@ public function testRemoveRootTypeDescriptorDefinesTypeIfSavingFails() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor = new BindingTypeDescriptor($type)); @@ -641,9 +628,9 @@ public function testRemoveRootTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Baz::clazz); - $type2 = new BindingType(Bar::clazz); - $type3 = new BindingType(Foo::clazz); + $type1 = new BindingType(Baz::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); + $type3 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -675,15 +662,15 @@ public function testRemoveRootTypeDescriptorsUnbindsCorrespondingBindings() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); - $bindingDescriptor1 = new ResourceBinding('/path1', Foo::clazz); - $bindingDescriptor2 = new ResourceBinding('/path2', Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); + $binding1 = new ResourceBinding('/path1', Foo::clazz); + $binding2 = new ResourceBinding('/path2', Bar::clazz); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type2)); - $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($bindingDescriptor1)); - $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($bindingDescriptor2)); + $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($binding1)); + $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($binding2)); $this->discovery->expects($this->at(0)) ->method('removeBindingType') @@ -695,11 +682,11 @@ public function testRemoveRootTypeDescriptorsUnbindsCorrespondingBindings() $this->discovery->expects($this->at(2)) ->method('removeBinding') - ->with($bindingDescriptor1->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding1, Expr::same(true))); $this->discovery->expects($this->at(3)) ->method('removeBinding') - ->with($bindingDescriptor2->getUuid()); + ->with(Bar::clazz, Expr::method('equals', $binding2, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -715,8 +702,8 @@ public function testClearRootTypeDescriptorsDefinesTypesIfSavingFails() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -760,8 +747,8 @@ public function testClearRootTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -791,7 +778,7 @@ public function testGetRootTypeDescriptor() { $this->initDefaultManager(); - $this->rootModuleFile->addTypeDescriptor($type = new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor($type = new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->assertSame($type, $this->manager->getRootTypeDescriptor(Foo::clazz)); } @@ -803,7 +790,7 @@ public function testGetRootTypeDescriptorFailsIfNotFoundInRoot() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor($type)); @@ -814,9 +801,9 @@ public function testGetRootTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); - $type3 = new BindingType(Baz::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); + $type3 = new BindingType(Baz::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -832,9 +819,9 @@ public function testFindRootTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); - $type3 = new BindingType(Baz::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); + $type3 = new BindingType(Baz::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -854,8 +841,8 @@ public function testHasRootTypeDescriptor() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type1)); $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor($type2)); @@ -869,8 +856,8 @@ public function testHasRootTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type1)); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type2)); @@ -887,8 +874,8 @@ public function testGetTypeDescriptor() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -933,9 +920,9 @@ public function testGetTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); - $type3 = new BindingType(Baz::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); + $type3 = new BindingType(Baz::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -954,9 +941,9 @@ public function testFindTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); - $type3 = new BindingType(Baz::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); + $type3 = new BindingType(Baz::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -976,8 +963,8 @@ public function testHasTypeDescriptor() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor($type1)); $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor($type2)); @@ -1002,8 +989,8 @@ public function testHasTypeDescriptors() { $this->initDefaultManager(); - $type1 = new BindingType(Foo::clazz); - $type2 = new BindingType(Bar::clazz); + $type1 = new BindingType(Foo::clazz, self::RESOURCE_BINDING); + $type2 = new BindingType(Bar::clazz, self::RESOURCE_BINDING); $this->rootModuleFile->addTypeDescriptor($typeDescriptor1 = new BindingTypeDescriptor($type1)); $this->moduleFile1->addTypeDescriptor($typeDescriptor2 = new BindingTypeDescriptor($type2)); @@ -1057,14 +1044,14 @@ public function testAddRootBindingDescriptor() /** * @expectedException \Puli\Manager\Api\Discovery\DuplicateBindingException */ - public function testAddRootBindingDescriptorFailsIfUuidDuplicatedInModule() + public function testAddRootBindingDescriptorFailsIfDuplicatedInModule() { $this->initDefaultManager(); $binding = new ResourceBinding('/path', Foo::clazz); $bindingDescriptor1 = new BindingDescriptor($binding); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = clone $bindingDescriptor1); $this->discovery->expects($this->never()) @@ -1079,14 +1066,14 @@ public function testAddRootBindingDescriptorFailsIfUuidDuplicatedInModule() /** * @expectedException \Puli\Manager\Api\Discovery\DuplicateBindingException */ - public function testAddRootBindingDescriptorFailsIfUuidDuplicatedInRoot() + public function testAddRootBindingDescriptorFailsIfDuplicatedInRoot() { $this->initDefaultManager(); $binding = new ResourceBinding('/path', Foo::clazz); $bindingDescriptor1 = new BindingDescriptor($binding); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor2 = clone $bindingDescriptor1); $this->discovery->expects($this->never()) @@ -1098,27 +1085,24 @@ public function testAddRootBindingDescriptorFailsIfUuidDuplicatedInRoot() $this->manager->addRootBindingDescriptor($bindingDescriptor1); } - public function testAddRootBindingDescriptorSucceedsIfUuidDuplicatedInRootAndOverride() + public function testAddRootBindingDescriptorSucceedsIfDuplicatedInRootAndOverride() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz, array(new BindingParameter('param'))); - $uuid = Uuid::uuid4(); - $binding1 = new ResourceBinding('/path1', Foo::clazz, array('param' => 'value'), 'xpath', $uuid); - $binding2 = new ResourceBinding('/path2', Foo::clazz, array('param' => 'value'), 'xpath', $uuid); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING, array(new BindingParameter('param'))); + $binding1 = new ResourceBinding('/path', Foo::clazz, array('param' => 'value'), 'xpath'); + $binding2 = new ResourceBinding('/path', Foo::clazz, array('param' => 'value'), 'xpath'); $bindingDescriptor1 = new BindingDescriptor($binding1); $bindingDescriptor2 = new BindingDescriptor($binding2); $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor($type)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1); - $this->discovery->expects($this->once()) - ->method('removeBinding') - ->with($uuid); + $this->discovery->expects($this->never()) + ->method('removeBinding'); - $this->discovery->expects($this->once()) - ->method('addBinding') - ->with($binding2); + $this->discovery->expects($this->never()) + ->method('addBinding'); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1131,16 +1115,19 @@ public function testAddRootBindingDescriptorSucceedsIfUuidDuplicatedInRootAndOve })); $this->manager->addRootBindingDescriptor($bindingDescriptor2, DiscoveryManager::OVERRIDE); + + $this->assertFalse($bindingDescriptor1->isEnabled()); + $this->assertTrue($bindingDescriptor2->isEnabled()); } /** * @expectedException \Puli\Manager\Api\Discovery\DuplicateBindingException */ - public function testAddRootBindingDescriptorDoesNotOverrideModuleUuids() + public function testAddRootBindingDescriptorDoesNotOverrideModuleBindings() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz, array(new BindingParameter('param'))); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING, array(new BindingParameter('param'))); $uuid = Uuid::uuid4(); $binding1 = new ResourceBinding('/path1', Foo::clazz, array('param' => 'value'), 'xpath', $uuid); $binding2 = new ResourceBinding('/path2', Foo::clazz, array('param' => 'value'), 'xpath', $uuid); @@ -1225,8 +1212,8 @@ public function testAddRootBindingDescriptorFailsIfTypeNotEnabled() { $this->initDefaultManager(); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->discovery->expects($this->never()) ->method('addBinding'); @@ -1244,8 +1231,8 @@ public function testAddRootBindingDescriptorFailsIfTypeNotEnabledAndIgnoreTypeNo { $this->initDefaultManager(); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->discovery->expects($this->never()) ->method('addBinding'); @@ -1262,8 +1249,8 @@ public function testAddRootBindingDescriptorDoesNotFailIfTypeNotEnabledAndIgnore $bindingDescriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); // The type is not enabled $this->discovery->expects($this->never()) @@ -1289,7 +1276,7 @@ public function testAddRootBindingDescriptorFailsIfMissingParameters() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING, array( new BindingParameter('param', BindingParameter::REQUIRED), )); @@ -1314,7 +1301,7 @@ public function testAddRootBindingDescriptorUnbindsIfSavingFailed() $bindingDescriptor = new BindingDescriptor($binding); $this->rootModuleFile->addBindingDescriptor($existingDescriptor); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->discovery->expects($this->once()) ->method('addBinding') @@ -1322,7 +1309,7 @@ public function testAddRootBindingDescriptorUnbindsIfSavingFailed() $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1346,12 +1333,12 @@ public function testRemoveRootBindingDescriptor() $binding = new ResourceBinding('/path', Foo::clazz); $bindingDescriptor = new BindingDescriptor($binding); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor); $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1387,7 +1374,7 @@ public function testRemoveRootBindingDescriptorIgnoresIfBindingNotInRootModule() $binding = new ResourceBinding('/path', Foo::clazz); $bindingDescriptor = new BindingDescriptor($binding); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor); $this->discovery->expects($this->never()) @@ -1432,8 +1419,8 @@ public function testRemoveRootBindingDescriptorWithTypeNotEnabled() $binding = new ResourceBinding('/path', Foo::clazz); $bindingDescriptor = new BindingDescriptor($binding); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor); $this->discovery->expects($this->never()) @@ -1458,12 +1445,12 @@ public function testRemoveRootBindingDescriptorBindsIfSavingFailed() $binding = new ResourceBinding('/path', Foo::clazz); $bindingDescriptor = new BindingDescriptor($binding); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor); $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->discovery->expects($this->once()) ->method('addBinding') @@ -1492,18 +1479,18 @@ public function testRemoveRootBindingDescriptors() $binding2 = new ResourceBinding('/path2', Foo::clazz); $binding3 = new ResourceBinding('/other3', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor3 = new BindingDescriptor($binding3)); $this->discovery->expects($this->at(0)) ->method('removeBinding') - ->with($binding1->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding1, Expr::same(true))); $this->discovery->expects($this->at(1)) ->method('removeBinding') - ->with($binding2->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding2, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1526,17 +1513,17 @@ public function testRemoveRootBindingDescriptorsBindsIfSavingFailed() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); $this->discovery->expects($this->at(0)) ->method('removeBinding') - ->with($binding1->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding1, Expr::same(true))); $this->discovery->expects($this->at(1)) ->method('removeBinding') - ->with($binding2->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding2, Expr::same(true))); $this->discovery->expects($this->at(2)) ->method('addBinding') @@ -1571,17 +1558,17 @@ public function testClearRootBindingDescriptors() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); $this->discovery->expects($this->at(0)) ->method('removeBinding') - ->with($binding1->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding1, Expr::same(true))); $this->discovery->expects($this->at(1)) ->method('removeBinding') - ->with($binding2->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding2, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1603,7 +1590,7 @@ public function testHasRootBindingDescriptor() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); @@ -1624,7 +1611,7 @@ public function testFindRootBindingDescriptors() $binding2 = new ResourceBinding('/path2', Foo::clazz, array(), 'glob', $uuid2); $binding3 = new ResourceBinding('/path3', Foo::clazz, array(), 'glob', $uuid3); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor3 = new BindingDescriptor($binding3)); @@ -1645,7 +1632,7 @@ public function testHasRootBindingDescriptors() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); @@ -1663,7 +1650,7 @@ public function testEnableBindingDescriptorBindsIfDisabled() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); $this->installInfo1->addDisabledBindingUuid($binding->getUuid()); @@ -1692,7 +1679,7 @@ public function testEnableBindingDescriptorDoesNothingIfAlreadyEnabled() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); $this->discovery->expects($this->never()) @@ -1732,7 +1719,7 @@ public function testEnableBindingDescriptorFailsIfBindingInRootModule() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($binding)); $this->discovery->expects($this->never()) @@ -1773,8 +1760,8 @@ public function testEnableBindingDescriptorFailsIfTypeNotEnabled() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); $this->discovery->expects($this->never()) @@ -1792,7 +1779,7 @@ public function testEnableBindingDescriptorUnbindsIfSavingFails() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($existingDescriptor = new BindingDescriptor(new ResourceBinding('/existing', Foo::clazz))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); $this->installInfo1->addDisabledBindingUuid($binding->getUuid()); @@ -1803,7 +1790,7 @@ public function testEnableBindingDescriptorUnbindsIfSavingFails() $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1825,7 +1812,7 @@ public function testEnableBindingDescriptorRestoresDisabledBindingsIfSavingFails $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); $this->installInfo1->addDisabledBindingUuid($binding->getUuid()); @@ -1835,7 +1822,7 @@ public function testEnableBindingDescriptorRestoresDisabledBindingsIfSavingFails $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1857,12 +1844,12 @@ public function testDisableBindingDescriptorUnbindsIfEnabled() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->jsonStorage->expects($this->once()) ->method('saveRootModuleFile') @@ -1885,7 +1872,7 @@ public function testDisableBindingDescriptorDoesNothingIfAlreadyDisabled() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); $this->installInfo1->addDisabledBindingUuid($binding->getUuid()); @@ -1926,7 +1913,7 @@ public function testDisableBindingDescriptorFailsIfBindingInRootModule() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor(new BindingDescriptor($binding)); $this->discovery->expects($this->never()) @@ -1967,8 +1954,8 @@ public function testDisableBindingDescriptorFailsIfTypeNotEnabled() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); $this->discovery->expects($this->never()) @@ -1987,14 +1974,14 @@ public function testDisableBindingDescriptorRebindsIfSavingFails() $binding = new ResourceBinding('/path1', Foo::clazz); $existing = new ResourceBinding('/existing', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($existing)); $this->installInfo1->addDisabledBindingUuid($existing->getUuid()); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->discovery->expects($this->once()) ->method('addBinding') @@ -2020,12 +2007,12 @@ public function testDisableBindingDescriptorRestoresEnabledBindingsIfSavingFails $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); $this->discovery->expects($this->once()) ->method('removeBinding') - ->with($binding->getUuid()); + ->with(Foo::clazz, Expr::method('equals', $binding, Expr::same(true))); $this->discovery->expects($this->once()) ->method('addBinding') @@ -2051,7 +2038,7 @@ public function testRemoveObsoleteDisabledBindingDescriptors() $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); $this->installInfo1->addDisabledBindingUuid($binding->getUuid()); $this->installInfo1->addDisabledBindingUuid(Uuid::uuid4()); @@ -2079,7 +2066,7 @@ public function testRemoveObsoleteDisabledBindingDescriptorsRevertsIfSavingFails $binding = new ResourceBinding('/path1', Foo::clazz); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->moduleFile1->addBindingDescriptor(new BindingDescriptor($binding)); $this->installInfo1->addDisabledBindingUuid($binding->getUuid()); $this->installInfo1->addDisabledBindingUuid($uuid1 = Uuid::uuid4()); @@ -2107,7 +2094,7 @@ public function testGetBindingDescriptor() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); @@ -2133,7 +2120,7 @@ public function testGetBindingDescriptors() $binding2 = new ResourceBinding('/path2', Foo::clazz); $binding3 = new ResourceBinding('/path3', Foo::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); $this->installInfo1->addDisabledBindingUuid($binding2->getUuid()); @@ -2158,7 +2145,7 @@ public function testFindBindingDescriptors() $binding2 = new ResourceBinding('/path2', Foo::clazz, array(), 'glob', $uuid2); $binding3 = new ResourceBinding('/path3', Foo::clazz, array(), 'glob', $uuid3); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); $this->moduleFile2->addBindingDescriptor($bindingDescriptor3 = new BindingDescriptor($binding3)); @@ -2179,7 +2166,7 @@ public function testHasBindingDescriptor() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); @@ -2195,7 +2182,7 @@ public function testHasBindingDescriptors() $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Bar::clazz); - $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->rootModuleFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor1 = new BindingDescriptor($binding1)); $this->moduleFile1->addBindingDescriptor($bindingDescriptor2 = new BindingDescriptor($binding2)); @@ -2220,7 +2207,7 @@ public function testBuildDiscovery() { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding = new ResourceBinding('/path', Foo::clazz); $this->rootModuleFile->addBindingDescriptor($bindingDescriptor = new BindingDescriptor($binding)); @@ -2241,7 +2228,7 @@ public function testBuildDiscoveryOnlyIncludesEnabledBindingsOfInstalledModules( { $this->initDefaultManager(); - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding1 = new ResourceBinding('/path1', Foo::clazz); $binding2 = new ResourceBinding('/path2', Foo::clazz); @@ -2281,7 +2268,7 @@ public function testBuildDiscoveryEmitsWarningsForBindingsWithUnknownParameters( $this->initDefaultManager(); // Unknown parameter - $type = new BindingType(Foo::clazz); + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING); $binding = new ResourceBinding('/path1', Foo::clazz, array('param' => 'value')); $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor($type)); @@ -2302,7 +2289,7 @@ public function testBuildDiscoveryEmitsWarningsForBindingsWithMissingParameters( $this->initDefaultManager(); // Required parameter is missing - $type = new BindingType(Foo::clazz, array( + $type = new BindingType(Foo::clazz, self::RESOURCE_BINDING, array( new BindingParameter('param', BindingParameter::REQUIRED), )); $binding = new ResourceBinding('/path1', Foo::clazz); @@ -2324,8 +2311,8 @@ public function testBuildDiscoveryEmitsWarningsForDuplicatedTypes() { $this->initDefaultManager(); - $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); - $this->moduleFile2->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz))); + $this->moduleFile1->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); + $this->moduleFile2->addTypeDescriptor(new BindingTypeDescriptor(new BindingType(Foo::clazz, self::RESOURCE_BINDING))); $this->discovery->expects($this->never()) ->method('addBindingType');