Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adapted to latest changes in Discovery #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"puli/manager": "^1.0-beta10",
"webmozart/console": "^1.0-beta4",
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/BindCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Puli\Cli\Util\ArgsUtil;
use Puli\Cli\Util\StringUtil;
use Puli\Discovery\Binding\ClassBinding;
use Puli\Discovery\Binding\ResourceBinding;
use Puli\Repository\Discovery\ResourceBinding;
use Puli\Manager\Api\Discovery\BindingDescriptor;
use Puli\Manager\Api\Discovery\BindingState;
use Puli\Manager\Api\Discovery\DiscoveryManager;
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/FindCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Puli\Cli\Util\StringUtil;
use Puli\Discovery\Api\Discovery;
use Puli\Discovery\Binding\ResourceBinding;
use Puli\Repository\Discovery\ResourceBinding;
use Puli\Repository\Api\ResourceRepository;
use RuntimeException;
use Webmozart\Console\Api\Args\Args;
Expand Down Expand Up @@ -164,7 +164,7 @@ private function findByBindingType($typeName)
{
$matches = array();

$expr = Expr::isInstanceOf('Puli\Discovery\Binding\ResourceBinding');
$expr = Expr::isInstanceOf('Puli\Repository\Discovery\ResourceBinding');

foreach ($this->discovery->findBindings($typeName, $expr) as $binding) {
/** @var ResourceBinding $binding */
Expand Down
20 changes: 18 additions & 2 deletions src/Handler/TypeCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ public function handleDefine(Args $args)
$this->parseParamDescriptions($args, $paramDescriptions);
$this->parseParams($args, $bindingParams);

$name = $args->getArgument('name');
$this->discoveryManager->addRootTypeDescriptor(new BindingTypeDescriptor(
new BindingType($args->getArgument('name'), $bindingParams),
new BindingType($name, $this->detectBindingClass($name), $bindingParams),
$args->getOption('description'),
$paramDescriptions
), $flags);
Expand Down Expand Up @@ -176,7 +177,7 @@ public function handleUpdate(Args $args)
}

$updatedDescriptor = new BindingTypeDescriptor(
new BindingType($name, $bindingParams),
new BindingType($name, $this->detectBindingClass($name), $bindingParams),
$description,
$paramDescriptions
);
Expand Down Expand Up @@ -363,4 +364,19 @@ private function typesEqual(BindingTypeDescriptor $descriptor1, BindingTypeDescr
$descriptor1->getParameterDescriptions() === $descriptor2->getParameterDescriptions() &&
$descriptor1->getType()->getParameters() === $descriptor2->getType()->getParameters();
}

/**
* Identify what type of binding class $name is.
*
* @param string $name
*/
private function detectBindingClass($name)
{
$bindingClass = 'Puli\Repository\Discovery\ResourceBinding';
if (class_exists($name) || interface_exists($name)) {
$bindingClass = 'Puli\Discovery\Binding\ClassBinding';
}

return $bindingClass;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this function a good idea? Is the logic good?

I need some feedback here

}
20 changes: 10 additions & 10 deletions tests/Handler/BindCommandHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Puli\Cli\Tests\Fixtures\Bar;
use Puli\Cli\Tests\Fixtures\Foo;
use Puli\Discovery\Binding\ClassBinding;
use Puli\Discovery\Binding\ResourceBinding;
use Puli\Repository\Discovery\ResourceBinding;
use Puli\Manager\Api\Discovery\BindingDescriptor;
use Puli\Manager\Api\Discovery\BindingState;
use Puli\Manager\Api\Discovery\DiscoveryManager;
Expand Down Expand Up @@ -780,7 +780,7 @@ public function testAddResourceBindingWithRelativePath()
$this->discoveryManager->expects($this->once())
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/path', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getBinding()->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(), $descriptor->getBinding()->getParameterValues());
Expand All @@ -797,7 +797,7 @@ public function testAddResourceBindingWithAbsolutePath()
$this->discoveryManager->expects($this->once())
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/path', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(), $descriptor->getBinding()->getParameterValues());
Expand All @@ -814,7 +814,7 @@ public function testAddResourceBindingWithLanguage()
$this->discoveryManager->expects($this->once())
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/path', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(), $descriptor->getBinding()->getParameterValues());
Expand Down Expand Up @@ -863,7 +863,7 @@ public function testAddBindingWithParameters()
$this->discoveryManager->expects($this->once())
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/path', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(
Expand Down Expand Up @@ -897,7 +897,7 @@ public function testAddBindingForce()
$this->discoveryManager->expects($this->once())
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor, $flags) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/path', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(), $descriptor->getBinding()->getParameterValues());
Expand Down Expand Up @@ -929,7 +929,7 @@ public function testUpdateResourceBinding()
$this->discoveryManager->expects($this->at(1))
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor, $flags) use ($uuid) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame($uuid, $descriptor->getUuid());
PHPUnit_Framework_Assert::assertSame('/new', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame('my/other', $descriptor->getTypeName());
Expand Down Expand Up @@ -960,7 +960,7 @@ public function testUpdateResourceBindingWithRelativePath()
$this->discoveryManager->expects($this->at(1))
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor, $flags) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/new', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(), $descriptor->getBinding()->getParameterValues());
Expand Down Expand Up @@ -1026,7 +1026,7 @@ public function testUpdateBindingWithUnsetParameter()
$this->discoveryManager->expects($this->at(1))
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor, $flags) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/path', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array('param1' => 'value1'), $descriptor->getBinding()->getParameterValues());
Expand All @@ -1053,7 +1053,7 @@ public function testUpdateBindingForce()
$this->discoveryManager->expects($this->at(1))
->method('addRootBindingDescriptor')
->willReturnCallback(function (BindingDescriptor $descriptor, $flags) {
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Discovery\Binding\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertInstanceOf('Puli\Repository\Discovery\ResourceBinding', $descriptor->getBinding());
PHPUnit_Framework_Assert::assertSame('/new', $descriptor->getBinding()->getQuery());
PHPUnit_Framework_Assert::assertSame(Foo::clazz, $descriptor->getTypeName());
PHPUnit_Framework_Assert::assertSame(array(), $descriptor->getBinding()->getParameterValues());
Expand Down
10 changes: 4 additions & 6 deletions tests/Handler/FindCommandHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
use PHPUnit_Framework_MockObject_MockObject;
use Puli\Cli\Handler\FindCommandHandler;
use Puli\Discovery\Api\Discovery;
use Puli\Discovery\Api\Type\BindingType;
use Puli\Discovery\Binding\ResourceBinding;
use Puli\Repository\Api\ResourceRepository;
use Puli\Repository\Discovery\ResourceBinding;
use Puli\Repository\Resource\Collection\ArrayResourceCollection;
use Puli\Repository\Resource\DirectoryResource;
use Puli\Repository\Resource\FileResource;
Expand Down Expand Up @@ -249,7 +248,7 @@ public function testFindByBindingType()
)));
$this->discovery->expects($this->once())
->method('findBindings')
->with('vendor/type', Expr::isInstanceOf('Puli\Discovery\Binding\ResourceBinding'))
->with('vendor/type', Expr::isInstanceOf('Puli\Repository\Discovery\ResourceBinding'))
->willReturn(array($binding1, $binding2));

$statusCode = $this->handler->handle($args, $this->io);
Expand Down Expand Up @@ -319,7 +318,7 @@ public function testFindByBindingTypeAndClass()
)));
$this->discovery->expects($this->once())
->method('findBindings')
->with('vendor/type', Expr::isInstanceOf('Puli\Discovery\Binding\ResourceBinding'))
->with('vendor/type', Expr::isInstanceOf('Puli\Repository\Discovery\ResourceBinding'))
->willReturn(array($binding1, $binding2));

$statusCode = $this->handler->handle($args, $this->io);
Expand All @@ -339,7 +338,6 @@ public function testFindByBindingTypeAndClass()
public function testFindByPathAndBindingType()
{
$args = self::$findCommand->parseArgs(new StringArgs('--path *pattern* --language xpath --type vendor/type'));
$type = new BindingType('vendor/type');

$binding1 = new ResourceBinding('/path1', 'vendor/type');
$binding2 = new ResourceBinding('/path2', 'vendor/type');
Expand Down Expand Up @@ -374,7 +372,7 @@ public function testFindByPathAndBindingType()

$this->discovery->expects($this->once())
->method('findBindings')
->with('vendor/type', Expr::isInstanceOf('Puli\Discovery\Binding\ResourceBinding'))
->with('vendor/type', Expr::isInstanceOf('Puli\Repository\Discovery\ResourceBinding'))
->willReturn(array($binding1, $binding2));

$statusCode = $this->handler->handle($args, $this->io);
Expand Down
Loading