From 19138ce2c1afbefe2b69e72ca12da3a6246dd53a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 9 Dec 2019 16:38:50 +0100 Subject: [PATCH 1/2] test with newer symfony versions and php 7.3 / 7.4 and cleanup build matrix --- .travis.yml | 11 ++++++----- composer.json | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 49b65644..69f86a49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,14 @@ language: php +# we seem to need the old trusty dist otherwise communication with jackrabbit fails +dist: trusty php: - 5.6 - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 env: - PACKAGE_VERSION=high @@ -19,16 +23,13 @@ cache: matrix: include: - php: 5.6 - env: PACKAGE_VERSION=low + env: COMPOSER_OPTIONS=--prefer-lowest --prefer-stable before_script: - - composer selfupdate - - if [[ "$PACKAGE_VERSION" == "high" ]]; then composer update --prefer-dist; fi - - if [[ "$PACKAGE_VERSION" == "low" ]]; then composer update --prefer-lowest --prefer-dist; fi + - composer update --prefer-dist ${COMPOSER_OPTIONS} - ./bin/jackrabbit.sh script: vendor/bin/phpunit notifications: irc: "irc.freenode.org#jackalope" - diff --git a/composer.json b/composer.json index c95b9b4b..cd4a2d04 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "psr/log": "~1.0", "phpcr/phpcr-api-tests": "2.1.19", - "symfony/console": "~2.0" + "symfony/console": "^2.3 || ^3.4 || ^4.3 || ^5.0" }, "autoload": { "psr-0": { "Jackalope\\": "src/" } From 59f12e197b9236ca88be005c1b03cf8df131eb2e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 11 Dec 2019 10:26:04 +0100 Subject: [PATCH 2/2] adjust to phpunit 7 --- .styleci.yml | 3 +- .travis.yml | 8 +- CHANGELOG.md | 5 + composer.json | 14 +- .../RepositoryFactoryJackrabbitTest.php | 17 +-- .../Transport/Jackrabbit/ClientTest.php | 121 ++++++++++-------- .../Transport/Jackrabbit/EventBufferTest.php | 54 +++----- .../Transport/Jackrabbit/RequestTest.php | 25 ++-- 8 files changed, 119 insertions(+), 128 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 4e1109ec..37d51bb8 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,5 +1,4 @@ preset: psr2 enabled: - - long_array_syntax - - duplicate_semicolon \ No newline at end of file + - duplicate_semicolon diff --git a/.travis.yml b/.travis.yml index 69f86a49..2cc10e05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,16 +3,10 @@ language: php dist: trusty php: - - 5.6 - - 7.0 - - 7.1 - 7.2 - 7.3 - 7.4 -env: - - PACKAGE_VERSION=high - sudo: false cache: @@ -22,7 +16,7 @@ cache: matrix: include: - - php: 5.6 + - php: 7.2 env: COMPOSER_OPTIONS=--prefer-lowest --prefer-stable before_script: diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6153b5..2cb2c9e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +1.4 (unreleased) +---------------- + +* PHP requirement bumped to 7.2, tested with up to 7.4. + 1.3 --- diff --git a/composer.json b/composer.json index cd4a2d04..0686693e 100644 --- a/composer.json +++ b/composer.json @@ -15,20 +15,22 @@ } ], "require": { - "php": "^5.6|^7.0", + "php": "^7.2", "ext-xml":"*", + "ext-dom": "*", "ext-curl":"*", - "phpcr/phpcr": "~2.1.2", + "phpcr/phpcr": "~2.1.5", "phpcr/phpcr-utils": "^1.3.0", - "jackalope/jackalope": "^1.3.4" + "jackalope/jackalope": "^1.3.5" }, "provide": { "jackalope/jackalope-transport": "1.3.0" }, "require-dev": { "psr/log": "~1.0", - "phpcr/phpcr-api-tests": "2.1.19", - "symfony/console": "^2.3 || ^3.4 || ^4.3 || ^5.0" + "phpcr/phpcr-api-tests": "2.1.21", + "symfony/console": "^2.3 || ^3.4 || ^4.3 || ^5.0", + "phpunit/phpunit": "^7.5" }, "autoload": { "psr-0": { "Jackalope\\": "src/" } @@ -42,7 +44,7 @@ "bin": ["bin/jackalope", "bin/jackrabbit.sh"], "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.x-dev" } } } diff --git a/tests/Jackalope/RepositoryFactoryJackrabbitTest.php b/tests/Jackalope/RepositoryFactoryJackrabbitTest.php index fabe1c5f..38ffcba8 100644 --- a/tests/Jackalope/RepositoryFactoryJackrabbitTest.php +++ b/tests/Jackalope/RepositoryFactoryJackrabbitTest.php @@ -2,29 +2,26 @@ namespace Jackalope; +use PHPCR\ConfigurationException; use PHPUnit\Framework\TestCase; class RepositoryFactoryJackrabbitTest extends TestCase { - /** - * @expectedException \PHPCR\ConfigurationException - * @expectedExceptionMessage missing - */ - public function testMissingRequired() + public function testMissingRequired(): void { $factory = new RepositoryFactoryJackrabbit(); + $this->expectException(ConfigurationException::class); + $this->expectExceptionMessage('missing'); $factory->getRepository(array()); } - /** - * @expectedException \PHPCR\ConfigurationException - * @expectedExceptionMessage unknown - */ - public function testExtraParameter() + public function testExtraParameter(): void { $factory = new RepositoryFactoryJackrabbit(); + $this->expectException(ConfigurationException::class); + $this->expectExceptionMessage('unknown'); $factory->getRepository(array( 'jackalope.jackrabbit_uri' => 'http://localhost', 'unknown' => 'garbage', diff --git a/tests/Jackalope/Transport/Jackrabbit/ClientTest.php b/tests/Jackalope/Transport/Jackrabbit/ClientTest.php index f7ba4bc7..2801c800 100644 --- a/tests/Jackalope/Transport/Jackrabbit/ClientTest.php +++ b/tests/Jackalope/Transport/Jackrabbit/ClientTest.php @@ -6,12 +6,27 @@ use Jackalope\Node; use Jackalope\Test\JackrabbitTestCase; use DOMDocument; +use Jackalope\Transport\Jackrabbit\Client; +use Jackalope\Transport\Jackrabbit\Request; +use PHPCR\LoginException; +use PHPCR\NodeType\NoSuchNodeTypeException; +use PHPCR\NoSuchWorkspaceException; +use PHPCR\RepositoryException; +use PHPUnit\Framework\MockObject\MockObject; +use Jackalope\Session; +use Jackalope\Workspace; +use PHPCR\ValueFormatException; +use Jackalope\NodeType\NodeTypeManager; +use Jackalope\ObjectManager; /** * TODO: this unit test contains some functional tests. we should separate functional and unit tests. */ class ClientTest extends JackrabbitTestCase { + /** + * @return MockObject|ClientMock + */ public function getTransportMock($args = 'testuri', $changeMethods = array()) { $factory = new Factory; @@ -20,7 +35,7 @@ public function getTransportMock($args = 'testuri', $changeMethods = array()) $mockMethods = array_merge(array_diff($defaultMockMethods, $changeMethods), array_diff($changeMethods, $defaultMockMethods)); return $this - ->getMockBuilder(__NAMESPACE__.'\ClientMock') + ->getMockBuilder(ClientMock::class) ->setMethods($mockMethods) ->setConstructorArgs(array($factory, $args)) ->getMock(); @@ -30,24 +45,21 @@ public function getRequestMock($response = '', $changeMethods = array()) { $defaultMockMethods = array('execute', 'executeDom', 'executeJson'); $mockMethods = array_merge(array_diff($defaultMockMethods, $changeMethods), array_diff($changeMethods, $defaultMockMethods)); - $request = $this->getMockBuilder('Jackalope\Transport\Jackrabbit\Request') + $request = $this->getMockBuilder(Request::class) ->disableOriginalConstructor() ->getMock($mockMethods); $request - ->expects($this->any()) ->method('execute') - ->will($this->returnValue($response)); + ->willReturn($response); $request - ->expects($this->any()) ->method('executeDom') - ->will($this->returnValue($response)); + ->willReturn($response); $request - ->expects($this->any()) ->method('executeJson') - ->will($this->returnValue($response)); + ->willReturn($response); return $request; } @@ -97,7 +109,6 @@ public function testBuildReportRequest() /** * @covers \Jackalope\Transport\Jackrabbit\Client::getRepositoryDescriptors - * @expectedException \PHPCR\RepositoryException */ public function testGetRepositoryDescriptorsEmptyBackendResponse() { @@ -107,8 +118,9 @@ public function testGetRepositoryDescriptorsEmptyBackendResponse() $request = $this->getRequestMock($dom, array('setBody')); $t->expects($this->once()) ->method('getRequest') - ->will($this->returnValue($request)); - $desc = $t->getRepositoryDescriptors(); + ->willReturn($request); + $this->expectException(RepositoryException::class); + $t->getRepositoryDescriptors(); } /** @@ -130,34 +142,34 @@ public function testGetRepositoryDescriptors() ->with($reportRequest); $desc = $t->getRepositoryDescriptors(); - $this->assertInternalType('array', $desc); - $this->assertInternalType('string', $desc['identifier.stability']); + $this->assertIsArray($desc); + $this->assertIsString($desc['identifier.stability']); $this->assertSame('identifier.stability.indefinite.duration', $desc['identifier.stability']); - $this->assertInternalType('array', $desc['node.type.management.property.types']); - $this->assertInternalType('string', $desc['node.type.management.property.types'][0]); + $this->assertIsArray($desc['node.type.management.property.types']); + $this->assertIsString($desc['node.type.management.property.types'][0]); $this->assertSame('2', $desc['node.type.management.property.types'][0]); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::getRequest - * @expectedException \PHPCR\RepositoryException */ public function testExceptionIfNotLoggedIn() { $factory = new Factory; $t = new ClientMock($factory, 'http://localhost:1/server'); + $this->expectException(RepositoryException::class); $t->getNodeTypes(); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::getRepositoryDescriptors - * @expectedException \PHPCR\RepositoryException */ public function testGetRepositoryDescriptorsNoserver() { $factory = new Factory; - $t = new \Jackalope\Transport\Jackrabbit\Client($factory, 'http://localhost:1/server'); - $d = $t->getRepositoryDescriptors(); + $t = new Client($factory, 'http://localhost:1/server'); + $this->expectException(RepositoryException::class); + $t->getRepositoryDescriptors(); } /** @@ -184,28 +196,27 @@ public function testBuildPropfindRequestArray() /** * @covers \Jackalope\Transport\Jackrabbit\Client::login - * @expectedException \PHPCR\RepositoryException */ public function testLoginAlreadyLoggedin() { $t = $this->getTransportMock(); $t->setCredentials('test'); + $this->expectException(RepositoryException::class); $t->login($this->credentials, $this->config['workspace']); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::login - * @expectedException \PHPCR\LoginException */ public function testLoginUnsportedCredentials() { $t = $this->getTransportMock(); + $this->expectException(LoginException::class); $t->login(new falseCredentialsMock(), $this->config['workspace']); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::login - * @expectedException \PHPCR\RepositoryException */ public function testLoginEmptyBackendResponse() { @@ -215,13 +226,13 @@ public function testLoginEmptyBackendResponse() $request = $this->getRequestMock($dom, array('setBody')); $t->expects($this->once()) ->method('getRequest') - ->will($this->returnValue($request)); + ->willReturn($request); + $this->expectException(RepositoryException::class); $t->login($this->credentials, 'tests'); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::login - * @expectedException \PHPCR\RepositoryException */ public function testLoginWrongWorkspace() { @@ -231,7 +242,8 @@ public function testLoginWrongWorkspace() $request = $this->getRequestMock($dom, array('setBody')); $t->expects($this->once()) ->method('getRequest') - ->will($this->returnValue($request)); + ->willReturn($request); + $this->expectException(RepositoryException::class); $t->login($this->credentials, 'tests'); } @@ -263,33 +275,33 @@ public function testLogin() /** * @covers \Jackalope\Transport\Jackrabbit\Client::login - * @expectedException \PHPCR\NoSuchWorkspaceException */ public function testLoginNoServer() { $factory = new Factory; - $t = new \Jackalope\Transport\Jackrabbit\Client($factory, 'http://localhost:1/server'); + $t = new Client($factory, 'http://localhost:1/server'); + $this->expectException(NoSuchWorkspaceException::class); $t->login($this->credentials, $this->config['workspace']); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::login - * @expectedException \PHPCR\NoSuchWorkspaceException */ public function testLoginNoSuchWorkspace() { $factory = new Factory; - $t = new \Jackalope\Transport\Jackrabbit\Client($factory, $this->config['url']); + $t = new Client($factory, $this->config['url']); + $this->expectException(NoSuchWorkspaceException::class); $t->login($this->credentials, 'not-an-existing-workspace'); } /** * @covers \Jackalope\Transport\Jackrabbit\Client::getNode - * @expectedException \PHPCR\RepositoryException */ public function testGetNodeWithoutAbsPath() { $t = $this->getTransportMock(); + $this->expectException(RepositoryException::class); $t->getNode('foo'); } @@ -304,7 +316,7 @@ public function testGetNode() $t->expects($this->once()) ->method('getRequest') ->with(Request::GET, '/foobar.0.json') - ->will($this->returnValue($request)); + ->willReturn($request); $json = $t->getNode('/foobar'); } @@ -320,7 +332,6 @@ public function testBuildLocateRequestMock() /** * @covers \Jackalope\Transport\Jackrabbit\Client::getNamespaces - * @expectedException \PHPCR\RepositoryException */ public function testGetNamespacesEmptyResponse() { @@ -331,8 +342,9 @@ public function testGetNamespacesEmptyResponse() $request = $this->getRequestMock($dom, array('setBody')); $t->expects($this->once()) ->method('getRequest') - ->will($this->returnValue($request)); + ->willReturn($request); + $this->expectException(RepositoryException::class); $t->getNamespaces(); } @@ -350,16 +362,16 @@ public function testGetNamespaces() $t->expects($this->once()) ->method('getRequest') ->with(Request::REPORT, 'testWorkspaceUri') - ->will($this->returnValue($request)); + ->willReturn($request); $request->expects($this->once()) ->method('setBody') ->with($reportRequest); $ns = $t->getNamespaces(); - $this->assertInternalType('array', $ns); + $this->assertIsArray($ns); foreach ($ns as $prefix => $uri) { - $this->assertInternalType('string', $prefix); - $this->assertInternalType('string', $uri); + $this->assertIsString($prefix); + $this->assertIsString($uri); } } @@ -376,7 +388,7 @@ protected function setUpNodeTypeMock($params, $fixture) $t->expects($this->once()) ->method('getRequest') ->with(Request::REPORT, 'testWorkspaceUriRoot') - ->will($this->returnValue($request)); + ->willReturn($request); $request->expects($this->once()) ->method('setBody') ->with($requestStr); @@ -410,7 +422,7 @@ public function testGetNodeTypes() $t = $this->setUpNodeTypeMock(array(), __DIR__.'/../../../fixtures/nodetypes.xml'); $nt = $t->getNodeTypes(); - $this->assertInternalType('array', $nt); + $this->assertIsArray($nt); $this->assertSame('mix:created', $nt[0]['name']); } @@ -422,8 +434,8 @@ public function testSpecificGetNodeTypes() $t = $this->setUpNodeTypeMock(array('nt:folder', 'nt:file'), __DIR__.'/../../../fixtures/small_nodetypes.xml'); $nt = $t->getNodeTypes(array('nt:folder', 'nt:file')); - $this->assertInternalType('array', $nt); - $this->assertSame(2, count($nt)); + $this->assertIsArray($nt); + $this->assertCount(2, $nt); $this->assertSame('nt:folder', $nt[0]['name']); $this->assertSame('nt:file', $nt[1]['name']); } @@ -435,7 +447,7 @@ public function testEmptyGetNodeTypes() { $t = $this->setUpNodeTypeMock(array(), __DIR__.'/../../../fixtures/empty.xml'); - $this->setExpectedException('\PHPCR\RepositoryException'); + $this->expectException('\PHPCR\RepositoryException'); $nt = $t->getNodeTypes(); } @@ -548,34 +560,35 @@ public function deleteNodesProvider() public function testOutOfRangeCharacterOccurrence($string, $isValid) { if (false === $isValid) { - $this->setExpectedException('PHPCR\ValueFormatException', 'Invalid character found in property "test". Are you passing a valid string?'); + $this->expectException(ValueFormatException::class); + $this->expectExceptionMessage('Invalid character found in property "test". Are you passing a valid string?'); } $t = $this->getTransportMock(); $factory = new Factory; - $session = $this->getMockBuilder('Jackalope\Session')->disableOriginalConstructor()->getMock(); - $workspace = $this->getMockBuilder('Jackalope\Workspace')->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); + $workspace = $this->createMock(Workspace::class); $session->expects($this->any()) ->method('getWorkspace') ->with() - ->will($this->returnValue($workspace)); + ->willReturn($workspace); $repository = $this->getMockBuilder('Jackalope\Repository')->disableOriginalConstructor()->getMock(); - $session->expects($this->any()) + $session ->method('getRepository') ->with() - ->will($this->returnValue($repository)); - $ntm = $this->getMockBuilder('Jackalope\NodeType\NodeTypeManager')->disableOriginalConstructor()->getMock(); - $workspace->expects($this->any()) + ->willReturn($repository); + $ntm = $this->createMock(NodeTypeManager::class); + $workspace ->method('getNodeTypeManager') ->with() - ->will($this->returnValue($ntm)); + ->willReturn($ntm); $nt = $this->getMockBuilder('Jackalope\NodeType\NodeType')->disableOriginalConstructor()->getMock(); - $ntm->expects($this->any()) + $ntm ->method('getNodeType') ->with() - ->will($this->returnValue($nt)); - $objectManager = $this->getMockBuilder('Jackalope\ObjectManager')->disableOriginalConstructor()->getMock(); + ->willReturn($nt); + $objectManager = $this->createMock(ObjectManager::class); $article = new Node($factory, array(), '/jcr:root', $session, $objectManager, true); $article->setProperty('test', $string); $t->updateProperties($article); diff --git a/tests/Jackalope/Transport/Jackrabbit/EventBufferTest.php b/tests/Jackalope/Transport/Jackrabbit/EventBufferTest.php index 5b7119df..81ffd071 100644 --- a/tests/Jackalope/Transport/Jackrabbit/EventBufferTest.php +++ b/tests/Jackalope/Transport/Jackrabbit/EventBufferTest.php @@ -9,6 +9,9 @@ use Jackalope\Factory; use PHPCR\NodeType\NodeTypeManagerInterface; use PHPCR\Observation\EventInterface; +use Jackalope\Transport\Jackrabbit\Client; +use Jackalope\NodeType\NodeTypeManager; +use PHPCR\RepositoryException; /** * Unit tests for the EventJournal @@ -45,27 +48,17 @@ class EventBufferTest extends TestCase public function setUp() { $this->factory = new Factory(); - $this->transport = $this - ->getMockBuilder('\Jackalope\Transport\Jackrabbit\Client') - ->disableOriginalConstructor() - ->getMock('fetchEventData') - ; + $this->transport = $this->createMock(Client::class); $this->session = $this->getSessionMock(array('getNode', 'getNodesByIdentifier')); $this->session - ->expects($this->any()) ->method('getNode') - ->will($this->returnValue(null)); + ->willReturn(null); $this->session - ->expects($this->any()) ->method('getNodesByIdentifier') - ->will($this->returnValue(array())); + ->willReturn([]); $this->filter = new EventFilter($this->factory, $this->session); - $this->nodeTypeManager = $this - ->getMockBuilder('Jackalope\NodeType\NodeTypeManager') - ->disableOriginalConstructor() - ->getMock() - ; + $this->nodeTypeManager = $this->createMock(NodeTypeManager::class); $this->buffer = new TestBuffer($this->factory, $this->filter, $this->transport, $this->nodeTypeManager, 'http://localhost:8080/server/tests/jcr%3aroot'); @@ -152,21 +145,18 @@ public function testExtractUserId() $this->assertEquals('', $res); } - /** - * @expectedException \PHPCR\RepositoryException - */ public function testExtractUserIdNoAuthor() { $xml = 'admin'; + + $this->expectException(RepositoryException::class); $this->getAndCallMethod($this->buffer, 'extractUserId', array($this->getDomElement($xml))); } - /** - * @expectedException \PHPCR\RepositoryException - */ public function testExtractUserIdNoName() { $xml = 'admin'; + $this->expectException(RepositoryException::class); $this->getAndCallMethod($this->buffer, 'extractUserId', array($this->getDomElement($xml))); } @@ -200,30 +190,24 @@ public function testExtractEventType() } } - /** - * @expectedException \PHPCR\RepositoryException - */ public function testExtractEventTypeInvalidType() { $xml = ''; + $this->expectException(RepositoryException::class); $this->getAndCallMethod($this->buffer, 'extractEventType', array($this->getDomElement($xml))); } - /** - * @expectedException \PHPCR\RepositoryException - */ public function testExtractEventTypeNoType() { $xml = ''; + $this->expectException(RepositoryException::class); $this->getAndCallMethod($this->buffer, 'extractEventType', array($this->getDomElement($xml))); } - /** - * @expectedException \PHPCR\RepositoryException - */ public function testExtractEventTypeMalformed() { $xml = 'some string'; + $this->expectException(RepositoryException::class); $this->getAndCallMethod($this->buffer, 'extractEventType', array($this->getDomElement($xml))); } @@ -233,7 +217,7 @@ public function testEventInfo() $this->assertCount(1, $events); $eventWithInfo = $events[0]; - $this->assertInstanceOf('Jackalope\Observation\Event', $eventWithInfo); + $this->assertInstanceOf(Event::class, $eventWithInfo); /** @var $eventWithInfo Event */ $eventInfo = $eventWithInfo->getInfo(); $this->assertEquals($this->expectedEventWithInfo->getInfo(), $eventInfo); @@ -243,7 +227,7 @@ public function testEventInfo() 'srcAbsPath' => '/my_node' ); - $this->assertEquals(count($expectedInfo), count($eventInfo)); + $this->assertCount(count($expectedInfo), $eventInfo); foreach ($expectedInfo as $key => $expectedValue) { $value = $eventInfo[$key]; @@ -254,13 +238,13 @@ public function testEventInfo() ->expects($this->at(0)) ->method('getNodeType') ->with('{internal}root') - ->will($this->returnValue(true)) + ->willReturn(true) ; $this->nodeTypeManager ->expects($this->at(1)) ->method('getNodeType') ->with('{internal}AccessControllable') - ->will($this->returnValue(true)) + ->willReturn(true) ; $this->assertTrue($eventWithInfo->getPrimaryNodeType()); @@ -328,10 +312,10 @@ public function testFetchPage() ->expects($this->once()) ->method('fetchEventData') ->with(7) - ->will($this->returnValue(array( + ->willReturn(array( 'data' => $dom, 'nextMillis' => false, - ))) + )) ; $buffer = new EventBuffer($this->factory, $this->filter, $this->transport, $this->nodeTypeManager, 'http://localhost:8080/server/tests/jcr%3aroot', $data); diff --git a/tests/Jackalope/Transport/Jackrabbit/RequestTest.php b/tests/Jackalope/Transport/Jackrabbit/RequestTest.php index c79e4075..1d56ba9e 100644 --- a/tests/Jackalope/Transport/Jackrabbit/RequestTest.php +++ b/tests/Jackalope/Transport/Jackrabbit/RequestTest.php @@ -5,6 +5,9 @@ use Jackalope\Factory; use Jackalope\Test\JackrabbitTestCase; use DOMDocument; +use Jackalope\Transport\Jackrabbit\Client; +use Jackalope\Transport\Jackrabbit\Request; +use PHPCR\SimpleCredentials; class RequestTest extends JackrabbitTestCase { @@ -20,22 +23,19 @@ protected function getCurlFixture($fixture = null, $httpCode = 200, $errno = nul $fixture = file_get_contents($fixture); } $curl - ->expects($this->any()) ->method('exec') - ->will($this->returnValue($fixture)); + ->willReturn($fixture); $curl - ->expects($this->any()) ->method('getinfo') ->with($this->equalTo(CURLINFO_HTTP_CODE)) - ->will($this->returnValue($httpCode)); + ->willReturn($httpCode); } if (null !== $errno) { $curl - ->expects($this->any()) ->method('errno') - ->will($this->returnValue($errno)); + ->willReturn($errno); } return $curl; @@ -43,10 +43,7 @@ protected function getCurlFixture($fixture = null, $httpCode = 200, $errno = nul public function getClientMock() { - return $this->getMockBuilder('Jackalope\\Transport\\Jackrabbit\\Client') - ->disableOriginalConstructor() - ->getMock() - ; + return $this->createMock(Client::class); } public function getRequest($fixture = null, $httpCode = 200, $errno = null) @@ -60,15 +57,15 @@ public function testExecuteDom() { $factory = new Factory; $request = $this - ->getMockBuilder('Jackalope\\Transport\\Jackrabbit\\Request') + ->getMockBuilder(Request::class) ->setMethods(array('execute')) ->setConstructorArgs(array($factory, $this->getClientMock(), $this->getCurlFixture(), null,null)) ->getMock(); $request->expects($this->once()) ->method('execute') - ->will($this->returnValue('')); + ->willReturn(''); - $this->assertInstanceOf('DOMDocument', $request->executeDom()); + $this->assertInstanceOf(DOMDocument::class, $request->executeDom()); } /** @@ -77,7 +74,7 @@ public function testExecuteDom() public function testPrepareRequestWithCredentials() { $request = $this->getRequest('fixtures/empty.xml'); - $request->setCredentials(new \PHPCR\SimpleCredentials('foo', 'bar')); + $request->setCredentials(new SimpleCredentials('foo', 'bar')); $request->getCurl()->expects($this->at(0)) ->method('setopt') ->with(CURLOPT_USERPWD, 'foo:bar');