diff --git a/lib/Gitlab/Api/Groups.php b/lib/Gitlab/Api/Groups.php index 94484ead5..03807e6c0 100644 --- a/lib/Gitlab/Api/Groups.php +++ b/lib/Gitlab/Api/Groups.php @@ -1,5 +1,7 @@ createOptionsResolver(); - $booleanNormalizer = function ($value) { + $booleanNormalizer = function (Options $resolver, $value) { return $value ? 'true' : 'false'; }; @@ -180,7 +182,7 @@ public function removeMember($group_id, $user_id) public function projects($id, array $parameters = []) { $resolver = $this->createOptionsResolver(); - $booleanNormalizer = function ($value) { + $booleanNormalizer = function (Options $resolver, $value) { return $value ? 'true' : 'false'; }; diff --git a/lib/Gitlab/Api/MergeRequests.php b/lib/Gitlab/Api/MergeRequests.php index 0c67d0cb4..d7b4ebb2e 100644 --- a/lib/Gitlab/Api/MergeRequests.php +++ b/lib/Gitlab/Api/MergeRequests.php @@ -1,5 +1,6 @@ createOptionsResolver(); - $datetimeNormalizer = function (\DateTimeInterface $value) { + $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value) { return $value->format('c'); }; $resolver->setDefined('iids') diff --git a/lib/Gitlab/Api/Projects.php b/lib/Gitlab/Api/Projects.php index f05415057..2337a9cec 100644 --- a/lib/Gitlab/Api/Projects.php +++ b/lib/Gitlab/Api/Projects.php @@ -1,5 +1,6 @@ createOptionsResolver(); - $booleanNormalizer = function ($value) { + $booleanNormalizer = function (Options $resolver, $value) { return $value ? 'true' : 'false'; }; $resolver->setDefined('archived') @@ -171,7 +172,7 @@ public function unarchive($project_id) public function pipelines($project_id, array $parameters = []) { $resolver = $this->createOptionsResolver(); - $booleanNormalizer = function ($value) { + $booleanNormalizer = function (Options $resolver, $value) { return $value ? 'true' : 'false'; }; @@ -430,7 +431,7 @@ public function enableDeployKey($project_id, $key_id) public function events($project_id, array $parameters = []) { $resolver = $this->createOptionsResolver(); - $datetimeNormalizer = function (\DateTimeInterface $value) { + $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value) { return $value->format('Y-m-d'); }; diff --git a/lib/Gitlab/Api/Repositories.php b/lib/Gitlab/Api/Repositories.php index 3a5092634..7ad01d35e 100644 --- a/lib/Gitlab/Api/Repositories.php +++ b/lib/Gitlab/Api/Repositories.php @@ -1,5 +1,6 @@ createOptionsResolver(); - $datetimeNormalizer = function (\DateTimeInterface $value) { + $datetimeNormalizer = function (Options $options, \DateTimeInterface $value) { return $value->format('c'); }; @@ -212,7 +213,7 @@ public function createCommit($project_id, array $parameters = []) ->setAllowedValues('actions', function (array $actions) { return !empty($actions); }) - ->setNormalizer('actions', function (OptionsResolver $resolver, array $actions) { + ->setNormalizer('actions', function (Options $resolver, array $actions) { $actionsOptionsResolver = new OptionsResolver(); $actionsOptionsResolver->setDefined('action') ->setRequired('action') diff --git a/lib/Gitlab/Api/Users.php b/lib/Gitlab/Api/Users.php index b23430078..fa63e0515 100644 --- a/lib/Gitlab/Api/Users.php +++ b/lib/Gitlab/Api/Users.php @@ -1,5 +1,7 @@ createOptionsResolver(); - $datetimeNormalizer = function (\DateTimeInterface $value) { + $datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value) { return $value->format('c'); }; diff --git a/test/Gitlab/Tests/Api/GroupsTest.php b/test/Gitlab/Tests/Api/GroupsTest.php index 1d244b967..5ba1324ca 100644 --- a/test/Gitlab/Tests/Api/GroupsTest.php +++ b/test/Gitlab/Tests/Api/GroupsTest.php @@ -24,6 +24,46 @@ public function shouldGetAllGroups() $this->assertEquals($expectedArray, $api->all(['page' => 1, 'per_page' => 10])); } + /** + * @test + */ + public function shouldGetAllGroupsWithBooleanParam() + { + $expectedArray = array( + array('id' => 1, 'name' => 'A group'), + array('id' => 2, 'name' => 'Another group'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups', ['all_available' => 'false']) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(['all_available' => false])); + } + + /** + * @test + */ + public function shouldGetAllGroupProjectsWithBooleanParam() + { + $expectedArray = array( + array('id' => 1, 'name' => 'A group'), + array('id' => 2, 'name' => 'Another group'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups/1/projects', ['archived' => 'false']) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->projects(1, ['archived' => false])); + } + /** * @test */ diff --git a/test/Gitlab/Tests/Api/MergeRequestsTest.php b/test/Gitlab/Tests/Api/MergeRequestsTest.php index e13a0aebd..30940b200 100644 --- a/test/Gitlab/Tests/Api/MergeRequestsTest.php +++ b/test/Gitlab/Tests/Api/MergeRequestsTest.php @@ -39,6 +39,34 @@ public function shouldGetAllWithParams() $this->assertEquals($expectedArray, $api->all(1, ['page' => 2, 'per_page' => 5, 'order_by' => 'updated_at', 'sort' => 'desc'])); } + /** + * @test + */ + public function shouldGetAllWithDateTimeParams() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $createdAfter = new \DateTime('2018-01-01 00:00:00'); + $createdBefore = new \DateTime('2018-01-31 00:00:00'); + + $expectedWithArray = [ + 'created_after' => $createdAfter->format(DATE_ATOM), + 'created_before' => $createdBefore->format(DATE_ATOM), + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests', $expectedWithArray) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals( + $expectedArray, + $api->all(1, ['created_after' => $createdAfter, 'created_before' => $createdBefore]) + ); + } + /** * @test */ diff --git a/test/Gitlab/Tests/Api/ProjectsTest.php b/test/Gitlab/Tests/Api/ProjectsTest.php index 599337328..0d9f07397 100644 --- a/test/Gitlab/Tests/Api/ProjectsTest.php +++ b/test/Gitlab/Tests/Api/ProjectsTest.php @@ -70,6 +70,18 @@ public function shouldGetOwnedProjects() $this->assertEquals($expectedArray, $api->all(['owned' => true])); } + /** + * @test + */ + public function shouldGetNotArchivedProjects() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['archived' => 'false']); + + $this->assertEquals($expectedArray, $api->all(['archived' => false])); + } + /** * @test */ @@ -228,6 +240,27 @@ public function shouldGetPipelines() $this->assertEquals($expectedArray, $api->pipelines(1)); } + /** + * @test + */ + public function shouldGetPipelinesWithBooleanParam() + { + $expectedArray = array( + array('id' => 1, 'status' => 'success','ref' => 'new-pipeline'), + array('id' => 2, 'status' => 'failed', 'ref' => 'new-pipeline'), + array('id' => 3, 'status' => 'pending', 'ref'=> 'test-pipeline') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/pipelines', ['yaml_errors' => 'false']) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->pipelines(1, ['yaml_errors' => false])); + } + /** * @test */ @@ -660,6 +693,34 @@ public function shouldGetEvents() $this->assertEquals($expectedArray, $api->events(1)); } + /** + * @test + */ + public function shouldGetEventsWithDateTimeParams() + { + $expectedArray = [ + ['id' => 1, 'title' => 'An event'], + ['id' => 2, 'title' => 'Another event'] + ]; + + $after = new \DateTime('2018-01-01 00:00:00'); + $before = new \DateTime('2018-01-31 00:00:00'); + + $expectedWithArray = [ + 'after' => $after->format('Y-m-d'), + 'before' => $before->format('Y-m-d'), + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/events', $expectedWithArray) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->events(1, ['after' => $after, 'before' => $before])); + } + /** * @test */ diff --git a/test/Gitlab/Tests/Api/RepositoriesTest.php b/test/Gitlab/Tests/Api/RepositoriesTest.php index 7020d98d0..350b3b389 100644 --- a/test/Gitlab/Tests/Api/RepositoriesTest.php +++ b/test/Gitlab/Tests/Api/RepositoriesTest.php @@ -257,6 +257,34 @@ public function shouldGetCommitsWithParams() $this->assertEquals($expectedArray, $api->commits(1, ['page' => 2, 'per_page' => 25, 'ref_name' => 'master'])); } + /** + * @test + */ + public function shouldGetCommitsWithTimeParams() + { + $expectedArray = [ + ['id' => 'abcd1234', 'title' => 'A commit'], + ['id' => 'efgh5678', 'title' => 'Another commit'] + ]; + + $since = new \DateTime('2018-01-01 00:00:00'); + $until = new \DateTime('2018-01-31 00:00:00'); + + $expectedWithArray = [ + 'since' => $since->format(DATE_ATOM), + 'until' => $until->format(DATE_ATOM), + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits', $expectedWithArray) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->commits(1, ['since' => $since, 'until' => $until])); + } + /** * @test */ diff --git a/test/Gitlab/Tests/Api/UsersTest.php b/test/Gitlab/Tests/Api/UsersTest.php index 6eedc93ac..d0bcc659a 100644 --- a/test/Gitlab/Tests/Api/UsersTest.php +++ b/test/Gitlab/Tests/Api/UsersTest.php @@ -44,6 +44,37 @@ public function shouldGetActiveUsers() $this->assertEquals($expectedArray, $api->all(['active' => true])); } + /** + * @test + */ + public function shouldGetUsersWithDateTimeParams() + { + $expectedArray = [ + ['id' => 1, 'name' => 'Matt'], + ['id' => 2, 'name' => 'John'], + ]; + + $createdAfter = new \DateTime('2018-01-01 00:00:00'); + $createdBefore = new \DateTime('2018-01-31 00:00:00'); + + $expectedWithArray = [ + 'created_after' => $createdAfter->format(DATE_ATOM), + 'created_before' => $createdBefore->format(DATE_ATOM), + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', $expectedWithArray) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals( + $expectedArray, + $api->all(['created_after' => $createdAfter, 'created_before' => $createdBefore]) + ); + } + /** * @test */