diff --git a/CHANGELOG.md b/CHANGELOG.md index 332dc34..e5fcb3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +4.x +=== + +4.4.3 +----- + +* Support phpcr-bundle 3. + 4.4.2 ----- diff --git a/composer.json b/composer.json index caf153a..4b51f2a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require-dev": { "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/phpcr-bundle": "^1.3 || ^2.0.0", + "doctrine/phpcr-bundle": "^1.3 || ^2.0 || ^3.0", "symfony/console": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", "symfony/dependency-injection": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", "symfony/doctrine-bridge": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 6e61652..9733efa 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -167,7 +167,14 @@ protected function getDbManager(string $type) )); } - $dbManager = new $className($this->getContainer()); + $refl = new \ReflectionClass($className); + if (1 === $refl->getConstructor()->getNumberOfParameters()) { + // phpcr-bundle < 3 + $dbManager = new $className(self::getContainer()); + } else { + // phpcr-bundle >= 3 + $dbManager = new $className(self::getContainer()->get('doctrine_phpcr'), self::getContainer()->get('doctrine_phpcr.initializer_manager')); + } $this->dbManagers[$type] = $dbManager; @@ -178,10 +185,10 @@ protected static function assertResponseSuccess(Response $response) { libxml_use_internal_errors(true); - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadHTML($response->getContent()); - $xpath = new \DOMXpath($dom); + $xpath = new \DOMXPath($dom); $result = $xpath->query('//div[contains(@class,"text-exception")]/h1'); $exception = null; if ($result->length) { diff --git a/src/Unit/Constraint/SchemaAcceptsXml.php b/src/Unit/Constraint/SchemaAcceptsXml.php index 46c1e82..d3913ae 100644 --- a/src/Unit/Constraint/SchemaAcceptsXml.php +++ b/src/Unit/Constraint/SchemaAcceptsXml.php @@ -35,7 +35,7 @@ public function matches($schemaFile): bool throw new \InvalidArgumentException(sprintf('Can only test a file if it contains 1 element, %d given', $configElement->length)); } - $configDom = new \DomDocument(); + $configDom = new \DOMDocument(); $configDom->appendChild($configDom->importNode($configElement->item(0), true)); libxml_use_internal_errors(true); diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index e063e02..5983b30 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -11,6 +11,8 @@ namespace Symfony\Cmf\Component\Testing\Tests\Functional; +use Doctrine\Bundle\PHPCRBundle\Initializer\InitializerManager; +use Doctrine\Bundle\PHPCRBundle\ManagerRegistryInterface; use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -25,12 +27,12 @@ class BaseTestCaseTest extends TestCase { /** - * @var ContainerInterface|MockObject + * @var ContainerInterface&MockObject */ private $container; /** - * @var KernelInterface|MockObject + * @var KernelInterface&MockObject */ private $kernel; @@ -47,20 +49,24 @@ class BaseTestCaseTest extends TestCase protected function setUp(): void { $this->container = $this->createMock(ContainerInterface::class); - $this->container->expects($this->any()) + $this->container ->method('get') - ->will($this->returnCallback(function ($name) { - $dic = ['test.client' => $this->client]; + ->willReturnCallback(function ($name) { + $dic = [ + 'test.client' => $this->client, + 'doctrine_phpcr' => $this->createMock(ManagerRegistryInterface::class), + 'doctrine_phpcr.initializer_manager' => $this->createMock(InitializerManager::class), + ]; return $dic[$name]; - })); + }); $this->kernel = $this->createMock(KernelInterface::class); - $this->kernel->expects($this->any()) + $this->kernel ->method('getContainer') ->willReturn($this->container) ; - $this->kernel->expects($this->any()) + $this->kernel ->method('getEnvironment') ->willReturn('phpcr') ; @@ -74,7 +80,7 @@ protected function setUp(): void $this->client = $this->createMock(Client::class); } - $this->client->expects($this->any()) + $this->client ->method('getContainer') ->willReturn($this->container); } @@ -122,6 +128,7 @@ public function provideTestDb() /** * @dataProvider provideTestDb + * * @depends testGetContainer */ public function testDb($dbName, $expected) diff --git a/tests/Unit/Constraint/SchemaAcceptsXmlTest.php b/tests/Unit/Constraint/SchemaAcceptsXmlTest.php index 29e8801..898de98 100644 --- a/tests/Unit/Constraint/SchemaAcceptsXmlTest.php +++ b/tests/Unit/Constraint/SchemaAcceptsXmlTest.php @@ -53,11 +53,11 @@ public function getAssertingData() $data = []; - $dom1 = new \DomDocument(); + $dom1 = new \DOMDocument(); $dom1->loadXML(''); $data[] = [[$dom1], $schema1, true]; - $dom2 = new \DomDocument(); + $dom2 = new \DOMDocument(); $dom2->loadXML(''); $data[] = [[$dom2], $schema1, false]; @@ -70,7 +70,7 @@ public function getAssertingData() public function testFailsIfNoConfigElementIsAvailable() { - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadXML(''); $constraint = new SchemaAcceptsXml([$dom]); diff --git a/tests/Unit/XmlSchemaTestCaseTest.php b/tests/Unit/XmlSchemaTestCaseTest.php index e70678e..d02ea45 100644 --- a/tests/Unit/XmlSchemaTestCaseTest.php +++ b/tests/Unit/XmlSchemaTestCaseTest.php @@ -17,14 +17,14 @@ class XmlSchemaTestCaseTest extends XmlSchemaTestCase { public function testAcceptsSingleDomsWithoutArray() { - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadXML(''); $this->assertSchemaAcceptsXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd'); } public function testNegativeAssertion() { - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadXML(''); $this->assertSchemaRefusesXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd');