Skip to content

Commit f7c1ab4

Browse files
committed
add basic class instanciation tests
1 parent b4ca8d5 commit f7c1ab4

File tree

4 files changed

+127
-1
lines changed

4 files changed

+127
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
vendor
1+
phpunit.xml
2+
composer.lock
3+
composer.phar
4+
vendor

phpunit.xml.dist

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="test/bootstrap.php"
13+
>
14+
<testsuites>
15+
<testsuite name="php-redmine-api Test Suite">
16+
<directory>./test/Redmine/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<groups>
21+
<exclude>
22+
<group>functional</group>
23+
</exclude>
24+
</groups>
25+
26+
<filter>
27+
<whitelist>
28+
<directory suffix=".php">./lib/Redmine/</directory>
29+
</whitelist>
30+
</filter>
31+
</phpunit>

test/Redmine/Tests/ClientTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Redmine\Tests;
4+
5+
use Redmine\Client;
6+
use Redmine\Exception\InvalidArgumentException;
7+
8+
class ClientTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @test
12+
*/
13+
public function shouldPassApiKeyToContructor()
14+
{
15+
$client = new Client('http://test.local', 'asdf');
16+
17+
$this->assertInstanceOf('Redmine\Client', $client);
18+
}
19+
20+
/**
21+
* @test
22+
*/
23+
public function shouldPassUsernameAndPasswordToContructor()
24+
{
25+
$client = new Client('http://test.local', 'username', 'pwd');
26+
27+
$this->assertInstanceOf('Redmine\Client', $client);
28+
}
29+
30+
/**
31+
* @test
32+
* @expectedException InvalidArgumentException
33+
*/
34+
public function shouldNotGetApiInstance()
35+
{
36+
$client = new Client('http://test.local', 'asdf');
37+
$client->api('do_not_exist');
38+
}
39+
40+
/**
41+
* @test
42+
* @dataProvider getApiClassesProvider
43+
*/
44+
public function shouldGetApiInstance($apiName, $class)
45+
{
46+
$client = new Client('http://test.local', 'asdf');
47+
$this->assertInstanceOf($class, $client->api($apiName));
48+
}
49+
50+
public function getApiClassesProvider()
51+
{
52+
return array(
53+
array('attachment', 'Redmine\Api\Attachment'),
54+
array('group', 'Redmine\Api\Group'),
55+
array('custom_fields', 'Redmine\Api\CustomField'),
56+
array('issue', 'Redmine\Api\Issue'),
57+
array('issue_category', 'Redmine\Api\IssueCategory'),
58+
array('issue_priority', 'Redmine\Api\IssuePriority'),
59+
array('issue_relation', 'Redmine\Api\IssueRelation'),
60+
array('issue_status', 'Redmine\Api\IssueStatus'),
61+
array('membership', 'Redmine\Api\Membership'),
62+
array('news', 'Redmine\Api\News'),
63+
array('project', 'Redmine\Api\Project'),
64+
array('query', 'Redmine\Api\Query'),
65+
array('role', 'Redmine\Api\Role'),
66+
array('time_entry', 'Redmine\Api\TimeEntry'),
67+
array('time_entry_activity', 'Redmine\Api\TimeEntryActivity'),
68+
array('tracker', 'Redmine\Api\Tracker'),
69+
array('user', 'Redmine\Api\User'),
70+
array('version', 'Redmine\Api\Version'),
71+
array('wiki', 'Redmine\Api\Wiki'),
72+
);
73+
}
74+
}

test/bootstrap.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
function includeIfExists($file)
4+
{
5+
if (file_exists($file)) {
6+
return include $file;
7+
}
8+
}
9+
10+
if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../.composer/autoload.php'))) {
11+
die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
12+
'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
13+
'php composer.phar install'.PHP_EOL);
14+
}
15+
16+
$loader->add('Redmine\Tests', __DIR__);
17+
18+
return $loader;

0 commit comments

Comments
 (0)