Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Fixed tests for PHP5
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Jun 2, 2016
1 parent 05be4f2 commit 6425f09
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Repository/Api/EditableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Cmf\Component\Resource\Repository\Api;

use InvalidArgumentException;
use Puli\Repository\Api\EditableRepository;
use Puli\Repository\Api\EditableRepository as PuliEditableRepository;
use Puli\Repository\Api\UnsupportedLanguageException;

/**
Expand All @@ -21,7 +21,7 @@
*
* @author Maximilian Berghoff <[email protected]>
*/
interface EditableRepository extends EditableRepository
interface EditableRepository extends PuliEditableRepository
{
/**
* Move all resources and their subgraphs found by $sourceQuery to the
Expand Down
2 changes: 0 additions & 2 deletions Repository/PhpcrOdmRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use Puli\Repository\Api\ResourceNotFoundException;
use Puli\Repository\Resource\Collection\ArrayResourceCollection;
use Symfony\Cmf\Component\Resource\Repository\Resource\PhpcrOdmResource;
use PHPCR\NodeInterface;
use DTL\Glob\GlobHelper;

class PhpcrOdmRepository extends AbstractPhpcrRepository
{
Expand Down
23 changes: 15 additions & 8 deletions Tests/Unit/Repository/PhpcrOdmRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\ODM\PHPCR\ChildrenCollection;
use Doctrine\ODM\PHPCR\UnitOfWork;
use PHPCR\NodeInterface;
use Prophecy\Argument;

class PhpcrOdmRepositoryTest extends AbstractPhpcrRepositoryTestCase
{
Expand All @@ -25,7 +26,6 @@ class PhpcrOdmRepositoryTest extends AbstractPhpcrRepositoryTestCase
private $childrenCollection;
private $uow;
private $document;
private $object;
private $child1;
private $child2;
private $node1;
Expand All @@ -39,8 +39,11 @@ public function setUp()
$this->childrenCollection = $this->prophesize(ChildrenCollection::class);
$this->uow = $this->prophesize(UnitOfWork::class);
$this->document = new \stdClass();

$this->child1 = new \stdClass();
$this->child2 = new \stdClass();

// because Prophecy doesn't care much about object IDs...
$this->child2 = new stdClass2();

$this->node1 = $this->prophesize(NodeInterface::class);
$this->node2 = $this->prophesize(NodeInterface::class);
Expand Down Expand Up @@ -105,7 +108,7 @@ public function testListChildren($basePath, $requestedPath, $canonicalPath, $abs
$this->assertInstanceOf('Puli\Repository\Resource\Collection\ArrayResourceCollection', $res);
$this->assertCount(2, $res);
$this->assertInstanceOf('Symfony\Cmf\Component\Resource\Repository\Resource\PhpcrOdmResource', $res[0]);
$this->assertEquals($canonicalPath.'/child2', $res[0]->getPath());
$this->assertEquals($canonicalPath.'/child1', $res[0]->getPath());
}

/**
Expand Down Expand Up @@ -207,13 +210,13 @@ public function testMoveMultiple()
$this->child2,
]);

$this->documentManager->getNodeForDocument($this->child1)->willReturn($this->node1->reveal());
$this->documentManager->getNodeForDocument($this->child2)->willReturn($this->node2->reveal());
$this->documentManager->getNodeForDocument(Argument::exact($this->child1))->willReturn($this->node1->reveal());
$this->documentManager->getNodeForDocument(Argument::exact($this->child2))->willReturn($this->node2->reveal());
$this->node1->getName()->willReturn('path1');
$this->node2->getName()->willReturn('path2');

$this->documentManager->move($this->child1, '/foo/path1')->shouldBeCalled();
$this->documentManager->move($this->child2, '/foo/path2')->shouldBeCalled();
$this->documentManager->move(Argument::exact($this->child1), '/foo/path1')->shouldBeCalled();
$this->documentManager->move(Argument::exact($this->child2), '/foo/path2')->shouldBeCalled();
$this->documentManager->flush()->shouldBeCalled();

$number = $this->getRepository()->move('/test/*', '/foo');
Expand All @@ -227,7 +230,7 @@ public function testMoveMultiple()
public function testMoveException()
{
$this->finder->find('/test/path1')->willReturn([
$this->document
$this->document,
]);
$this->documentManager->move($this->document, '/test/path2')->willThrow(new \InvalidArgumentException('test'));

Expand All @@ -251,3 +254,7 @@ protected function getRepository($path = null)
return $repository;
}
}

class stdClass2 extends \stdClass
{
}
30 changes: 15 additions & 15 deletions Tests/Unit/Repository/Resource/Metadata/PhpcrMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public function setUp()
$this->metadata = new PhpcrMetadata($this->node->reveal());
}

/**
* @dataProvider provideMethods
*/
public function testMethods($method, $mixinType, $hasMixin, $propertyName, $propertyValue, $expectedValue)
{
$this->node->isNodeType($mixinType)->willReturn($hasMixin);
$this->node->getProperty($propertyName)->willReturn($this->property->reveal());
$this->property->getDate()->willReturn($propertyValue);

$res = $this->metadata->{$method}();
$this->assertEquals($expectedValue, $res);
}

public function provideMethods()
{
return array(
Expand All @@ -33,15 +46,15 @@ public function provideMethods()
'mix:created',
true,
'jcr:created',
new \DateTime('2015-01-01'),
new \DateTime('2015-01-01T00:00:00Z'),
1420070400,
),
array(
'getModificationTime',
'mix:lastModified',
true,
'jcr:lastModified',
new \DateTime('2015-01-01'),
new \DateTime('2015-01-01T00:00:00Z'),
1420070400,
),
array(
Expand Down Expand Up @@ -70,17 +83,4 @@ public function provideMethods()
),
);
}

/**
* @dataProvider provideMethods
*/
public function testMethods($method, $mixinType, $hasMixin, $propertyName, $propertyValue, $expectedValue)
{
$this->node->isNodeType($mixinType)->willReturn($hasMixin);
$this->node->getProperty($propertyName)->willReturn($this->property->reveal());
$this->property->getDate()->willReturn($propertyValue);

$res = $this->metadata->{$method}();
$this->assertEquals($expectedValue, $res);
}
}

0 comments on commit 6425f09

Please sign in to comment.