Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for updating groups #359

Merged
merged 7 commits into from
Jan 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move tests for Group::create into separate test case
Art4 committed Jan 10, 2024
commit 06f6345b5945282ec45029d1ad69f544cd60dc1e
74 changes: 74 additions & 0 deletions tests/Unit/Api/Group/CreateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace Redmine\Tests\Unit\Api\Group;

use PHPUnit\Framework\TestCase;
use Redmine\Api\Group;
use Redmine\Client\Client;
use Redmine\Exception\MissingParameterException;

/**
* @covers \Redmine\Api\Group::create
*/
class CreateTest extends TestCase
{
/**
* @covers ::create
*/
public function testCreateCallsPost()
{
// Test values
$response = 'API Response';
$postParameter = [
'name' => 'Group Name',
];

// Create the used mock objects
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('requestPost')
->with(
$this->logicalAnd(
$this->stringStartsWith('/groups'),
$this->logicalXor(
$this->stringEndsWith('.json'),
$this->stringEndsWith('.xml')
)
),
$this->stringContains('<group><name>Group Name</name></group>')
)
->willReturn(true);
$client->expects($this->exactly(1))
->method('getLastResponseBody')
->willReturn($response);

// Create the object under test
$api = new Group($client);

// Perform the tests
$this->assertSame($response, $api->create($postParameter));
}

/**
* @covers ::create
*/
public function testCreateThrowsExceptionIfNameIsMissing()
{
// Test values
$postParameter = [];

// Create the used mock objects
$client = $this->createMock(Client::class);

// Create the object under test
$api = new Group($client);

$this->expectException(MissingParameterException::class);
$this->expectExceptionMessage('Theses parameters are mandatory: `name`');

// Perform the tests
$api->create($postParameter);
}
}
70 changes: 2 additions & 68 deletions tests/Unit/Api/GroupTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

declare(strict_types=1);

namespace Redmine\Tests\Unit\Api;

use PHPUnit\Framework\TestCase;
use Redmine\Api\Group;
use Redmine\Client\Client;
use Redmine\Exception\MissingParameterException;
use Redmine\Tests\Fixtures\MockClient;

/**
@@ -341,73 +342,6 @@ public function testRemoveCallsDelete()
$this->assertSame($expectedReturn, $api->remove(5));
}

/**
* Test create().
*
* @covers ::create
* @covers ::post
* @test
*/
public function testCreateCallsPost()
{
// Test values
$response = 'API Response';
$postParameter = [
'name' => 'Group Name',
];

// Create the used mock objects
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('requestPost')
->with(
$this->logicalAnd(
$this->stringStartsWith('/groups'),
$this->logicalXor(
$this->stringEndsWith('.json'),
$this->stringEndsWith('.xml')
)
),
$this->stringContains('<group><name>Group Name</name></group>')
)
->willReturn(true);
$client->expects($this->exactly(1))
->method('getLastResponseBody')
->willReturn($response);

// Create the object under test
$api = new Group($client);

// Perform the tests
$this->assertSame($response, $api->create($postParameter));
}

/**
* Test create().
*
* @covers ::create
* @covers ::post
*
* @test
*/
public function testCreateThrowsExceptionIfNameIsMissing()
{
// Test values
$postParameter = [];

// Create the used mock objects
$client = $this->createMock(Client::class);

// Create the object under test
$api = new Group($client);

$this->expectException(MissingParameterException::class);
$this->expectExceptionMessage('Theses parameters are mandatory: `name`');

// Perform the tests
$api->create($postParameter);
}

/**
* Test removeUser().
*