From 275a30cf17b7fcef1a8369d6a688a7e4b7690f7e Mon Sep 17 00:00:00 2001 From: Aranya Sen Date: Thu, 30 Apr 2020 11:43:07 +0530 Subject: [PATCH] Refactor test strcuture to PSR-4 * Added PSR-4 mapping in composer * Updated namespaces in tests * Rename any files that do not conform to PSR-4 * Updated tests to "use" classes instead of requiring those --- composer.json | 9 +++++++-- test/AgileBoardSettingTest.php | 8 ++++---- test/AttachmentTest.php | 18 +++++++++--------- test/AutoloadingTest.php | 3 ++- test/BaseObjectTest.php | 6 +++--- test/ConnectionTest.php | 10 ++++------ test/CurrentUserTest.php | 7 ++++--- test/EnumFieldTest.php | 7 +++++-- test/ExceptionTest.php | 9 ++++----- test/IssueTest.php | 8 +++++--- test/OwnedFieldBundleTest.php | 7 +++++-- test/RoleTest.php | 9 +++++---- .../{testconnection.php => TestConnection.php} | 4 +++- test/VersionTest.php | 7 ++++--- test/WorkitemTest.php | 8 +++++--- test/requirements.php | 6 ------ 16 files changed, 69 insertions(+), 57 deletions(-) rename test/{testconnection.php => TestConnection.php} (85%) delete mode 100644 test/requirements.php diff --git a/composer.json b/composer.json index 72d3276..ea9474f 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,13 @@ } ], "autoload": { - "psr-0": { - "YouTrack\\": "./" + "psr-4": { + "YouTrack\\": "YouTrack/" + } + }, + "autoload-dev": { + "psr-4": { + "YouTrack\\Test\\": "test/" } }, "require": { diff --git a/test/AgileBoardSettingTest.php b/test/AgileBoardSettingTest.php index 9b58ad5..21abb39 100644 --- a/test/AgileBoardSettingTest.php +++ b/test/AgileBoardSettingTest.php @@ -1,8 +1,8 @@ */ -class AttachmentsTest extends \PHPUnit_Framework_TestCase +class AttachmentTest extends \PHPUnit_Framework_TestCase { - private $singleAttachmentFile = 'test/testdata/attachment.xml'; + private $singleAttachmentFile = __DIR__ . '/testdata/attachment.xml'; public function testCanCreateSimpleAttachment() { @@ -99,12 +99,12 @@ public function testCreateAttachmentFromAttachment() { $attachment = $this->createAttachment(); - $expectedResult = unserialize(file_get_contents('test/testdata/request-response-create-attachment-serialized.txt')); + $expectedResult = unserialize(file_get_contents(__DIR__ . '/testdata/request-response-create-attachment-serialized.txt')); /** * @var \YouTrack\Connection $youtrack */ - $youtrackBuilder = $this->getMockBuilder('\\YouTrack\\TestConnection'); + $youtrackBuilder = $this->getMockBuilder('YouTrack\\Test\\TestConnection'); $youtrackBuilder->setMethods(['request']); $youtrack = $youtrackBuilder->getMock(); @@ -141,7 +141,7 @@ public function testCreateAttachment($name, $authorLogin, $created, $group, $par $expectedUrl = '/issue/' . rawurlencode($issueId) . '/attachment?' . http_build_query($params); $expectedResult = 'myResponseValue'; - $youtrackBuilder = $this->getMockBuilder('\\YouTrack\\TestConnection'); + $youtrackBuilder = $this->getMockBuilder('YouTrack\\Test\\TestConnection'); $youtrackBuilder->setMethods(['request']); $youtrack = $youtrackBuilder->getMock(); @@ -158,7 +158,7 @@ public function testCreateAttachment($name, $authorLogin, $created, $group, $par public function testCreateAttachmentThrowsExceptionOnNonExistingFile() { - $youtrackBuilder = $this->getMockBuilder('\\YouTrack\\TestConnection'); + $youtrackBuilder = $this->getMockBuilder('YouTrack\\Test\\TestConnection'); $youtrackBuilder->setMethods(['request']); $youtrack = $youtrackBuilder->getMock(); diff --git a/test/AutoloadingTest.php b/test/AutoloadingTest.php index 6196edc..fffc3b7 100644 --- a/test/AutoloadingTest.php +++ b/test/AutoloadingTest.php @@ -1,5 +1,6 @@ assertInstanceOf('\YouTrack\TestConnection', $con); + $this->assertInstanceOf('YouTrack\Test\TestConnection', $con); } public function testIncorrectLoginThrowsException() { $con = new TestConnection(); - $refl = new \ReflectionClass('\YouTrack\TestConnection'); + $refl = new \ReflectionClass('YouTrack\Test\TestConnection'); $method = $refl->getMethod('handleLoginResponse'); $method->setAccessible(true); - $content = file_get_contents('test/testdata/incorrect-login.http'); + $content = file_get_contents(__DIR__ . '/testdata/incorrect-login.http'); $response = [ 'http_code' => 403 ]; diff --git a/test/CurrentUserTest.php b/test/CurrentUserTest.php index 4c7cadc..754ad5e 100644 --- a/test/CurrentUserTest.php +++ b/test/CurrentUserTest.php @@ -1,6 +1,7 @@ 200, ]; $content = ''; - $e = new Exception($url, $response, $content); + $e = new YouTrackException($url, $response, $content); $this->assertEquals("Error for 'http://example.com': 200", $e->getMessage()); } @@ -30,7 +29,7 @@ public function testConstruct02() 'http_code' => 404, ]; $content = ''; - $e = new Exception($url, $response, $content); + $e = new YouTrackException($url, $response, $content); $this->assertEquals("Error for 'http://example.com': 404", $e->getMessage()); } @@ -42,7 +41,7 @@ public function testConstruct03() 'content_type' => 'text/html; charset=utf8', ]; $content = ''; - $e = new Exception($url, $response, $content); + $e = new YouTrackException($url, $response, $content); $this->assertEquals("Error for 'http://example.com': 500", $e->getMessage()); } diff --git a/test/IssueTest.php b/test/IssueTest.php index 0d10743..b4a603f 100644 --- a/test/IssueTest.php +++ b/test/IssueTest.php @@ -1,6 +1,8 @@