Skip to content

Commit 41aea59

Browse files
committed
Add more tests
1 parent 71bc79a commit 41aea59

12 files changed

+90
-25
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
resolveDependencies="true">
1212

1313
<extensions>
14-
<extension class="Xepozz\InternalMocker\Tests\Listener"/>
14+
<extension class="Xepozz\InternalMocker\Tests\MockerExtension"/>
1515
</extensions>
1616
<php>
1717
<ini name="error_reporting" value="-1"/>

src/Mocker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function load(array $mocks): void
2424
}
2525
file_put_contents($configPath, $data);
2626

27-
require $configPath;
27+
require_once $configPath;
2828
}
2929

3030
public function generate(array $mocks): string

tests/Integration/DateTime.php

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

44
namespace Xepozz\InternalMocker\Tests\Integration;
55

6-
class DateTime
6+
final class DateTime
77
{
88
public function run(): int
99
{

tests/Integration/DateTimeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testRun2()
2020
$obj = new DateTime();
2121

2222
MockerState::addCondition(
23-
'Xepozz\InternalMocker\Tests\Integration',
23+
__NAMESPACE__,
2424
'time',
2525
[],
2626
100
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Xepozz\InternalMocker\Tests\Integration;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Xepozz\InternalMocker\MockerState;
9+
use Xepozz\InternalMocker\Tests\MockerExtension;
10+
11+
final class EarlyMockInitializationSucceedTest extends TestCase
12+
{
13+
public function __construct(?string $name = null, array $data = [], $dataName = '')
14+
{
15+
MockerExtension::load();
16+
parent::__construct($name, $data, $dataName);
17+
}
18+
19+
/**
20+
* @dataProvider dataProvider
21+
*/
22+
public function testRun(UseInSucceedDataProviderStub $object): void
23+
{
24+
MockerState::addCondition(
25+
__NAMESPACE__,
26+
'serialize',
27+
['asd'],
28+
'not serialized'
29+
);
30+
$this->assertEquals('not serialized', $object->run('asd'));
31+
}
32+
33+
public function dataProvider(): array
34+
{
35+
return [
36+
[new UseInSucceedDataProviderStub()],
37+
];
38+
}
39+
}

tests/Integration/FunctionExistsTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
use PHPUnit\Framework\TestCase;
88
use RuntimeException;
99
use Xepozz\InternalMocker\MockerState;
10-
use Xepozz\InternalMocker\Stub;
1110

12-
class FunctionExistsTest extends TestCase
11+
final class FunctionExistsTest extends TestCase
1312
{
1413
public function testSuccess()
1514
{
1615
MockerState::addCondition(
17-
'Xepozz\\InternalMocker',
16+
__NAMESPACE__,
1817
'function_exists',
1918
['function_exists'],
2019
false
@@ -27,7 +26,7 @@ public function testSuccess()
2726
public function testFail()
2827
{
2928
MockerState::addCondition(
30-
'Xepozz\\InternalMocker',
29+
__NAMESPACE__,
3130
'function_exists',
3231
['function_exists'],
3332
true

tests/Integration/IgnoreArgumentsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHPUnit\Framework\TestCase;
88
use Xepozz\InternalMocker\MockerState;
99

10-
class IgnoreArgumentsTest extends TestCase
10+
final class IgnoreArgumentsTest extends TestCase
1111
{
1212
/**
1313
* @dataProvider dataProvider

tests/Integration/StrContains.php

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

44
namespace Xepozz\InternalMocker\Tests\Integration;
55

6-
class StrContains
6+
final class StrContains
77
{
88
public function run(string $haystack, string $needle): bool
99
{

tests/Integration/StrContainsTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Xepozz\InternalMocker\Tests\Integration;
56

67
use PHPUnit\Framework\TestCase;
78
use Xepozz\InternalMocker\MockerState;
89

9-
class StrContainsTest extends TestCase
10+
final class StrContainsTest extends TestCase
1011
{
11-
public function testRun()
12+
public function testRun(): void
1213
{
1314
$obj = new StrContains();
1415

1516
$this->assertFalse($obj->run('string', 'str'));
1617
}
1718

18-
public function testRun2()
19+
public function testRun2(): void
1920
{
2021
$obj = new StrContains();
2122

2223
$this->assertFalse($obj->run('string2', 'str'));
2324
}
2425

25-
public function testRun3()
26+
public function testRun3(): void
2627
{
2728
$obj = new StrContains();
2829

2930
$this->assertTrue($obj->run('string3', 'str'));
3031
}
3132

32-
public function testRun4()
33+
public function testRun4(): void
3334
{
3435
$obj = new StrContains();
3536

3637
MockerState::addCondition(
37-
'Xepozz\InternalMocker\Tests\Integration',
38+
__NAMESPACE__,
3839
'str_contains',
3940
['string4', 'str'],
4041
false

src/Stub.php renamed to tests/Integration/Stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace Xepozz\InternalMocker;
5+
namespace Xepozz\InternalMocker\Tests\Integration;
66

77
use RuntimeException;
88

9-
class Stub
9+
final class Stub
1010
{
1111
public function __construct()
1212
{

0 commit comments

Comments
 (0)