Skip to content

Commit b25e05c

Browse files
committed
Add PHPUnit
1 parent e5b7de7 commit b25e05c

File tree

8 files changed

+86
-28
lines changed

8 files changed

+86
-28
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
},
2929
"require": {
3030
"php": ">=5.3.0"
31+
},
32+
"require-dev": {
33+
"phpunit/phpunit": "4.*"
3134
}
3235
}

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit>
2+
<testsuites>
3+
<testsuite name="CodeMommy AutoloadPHP">
4+
<directory>test</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

source/Autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* CodeMommy AutoloadPHP
5-
* @author Candison November <www.kandisheng.com>
5+
* @author Candison November <www.kandisheng.com>
66
*/
77

88
namespace CodeMommy\AutoloadPHP;

test/AutoloadTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* @author Candison November <www.kandisheng.com>
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
require_once(__DIR__ . '/../vendor/autoload.php');
10+
11+
use PHPUnit\Framework\TestCase;
12+
use CodeMommy\AutoloadPHP\Autoload;
13+
use NamespaceOne\ClassOne;
14+
use Root\NamespaceTwo\ClassTwo;
15+
use Root\NamespaceThree\ClassThree;
16+
17+
class AutoloadTest extends TestCase
18+
{
19+
/**
20+
* Test Load
21+
* @return void
22+
*/
23+
public function testLoad1()
24+
{
25+
Autoload::load(__DIR__, '');
26+
$this->assertEquals(ClassOne::show(), 'ClassOne');
27+
}
28+
29+
/**
30+
* Test Load
31+
* @return void
32+
*/
33+
public function testLoad2()
34+
{
35+
Autoload::load(__DIR__, 'Root');
36+
$this->assertEquals(ClassTwo::show(), 'ClassTwo');
37+
}
38+
39+
/**
40+
* Test File
41+
* @return void
42+
*/
43+
public function testFile()
44+
{
45+
Autoload::file(__DIR__ . '/NamespaceThree/ClassThree.php', 'Root\NamespaceThree\ClassThree');
46+
$this->assertEquals(ClassThree::show(), 'ClassThree');
47+
}
48+
}

test/NamespaceOne/ClassOne.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
<?php
22

33
/**
4-
* @author Candison November <www.kandisheng.com>
4+
* @author Candison November <www.kandisheng.com>
55
*/
66

77
namespace NamespaceOne;
88

9+
/**
10+
* Class ClassOne
11+
* @package NamespaceOne
12+
*/
913
class ClassOne
1014
{
15+
/**
16+
* @return string
17+
*/
1118
public static function show()
1219
{
13-
echo 'ClassOne';
20+
return 'ClassOne';
1421
}
1522
}

test/NamespaceThree/ClassThree.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
<?php
22

33
/**
4-
* @author Candison November <www.kandisheng.com>
4+
* @author Candison November <www.kandisheng.com>
55
*/
66

77
namespace Root\NamespaceThree;
88

9+
/**
10+
* Class ClassThree
11+
* @package Root\NamespaceThree
12+
*/
913
class ClassThree
1014
{
15+
/**
16+
* @return string
17+
*/
1118
public static function show()
1219
{
13-
echo 'ClassThree';
20+
return 'ClassThree';
1421
}
1522
}

test/NamespaceTwo/ClassTwo.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
<?php
22

33
/**
4-
* @author Candison November <www.kandisheng.com>
4+
* @author Candison November <www.kandisheng.com>
55
*/
66

77
namespace Root\NamespaceTwo;
88

9+
/**
10+
* Class ClassTwo
11+
* @package Root\NamespaceTwo
12+
*/
913
class ClassTwo
1014
{
15+
/**
16+
* @return string
17+
*/
1118
public static function show()
1219
{
13-
echo 'ClassTwo';
20+
return 'ClassTwo';
1421
}
1522
}

test/autoload.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)