-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPatchTest.php
More file actions
71 lines (61 loc) · 2.13 KB
/
PatchTest.php
File metadata and controls
71 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace PhpSchool\PhpWorkshopTest;
use PhpSchool\PhpWorkshop\CodeInsertion;
use PhpSchool\PhpWorkshop\Patch;
use PHPUnit\Framework\TestCase;
class PatchTest extends TestCase
{
public function testWithInsertion(): void
{
$patch = new Patch();
$insertion = new CodeInsertion(CodeInsertion::TYPE_BEFORE, 'MEH');
$new = $patch->withInsertion($insertion);
$this->assertNotSame($patch, $new);
$this->assertEmpty($patch->getModifiers());
$this->assertEquals([$insertion], $new->getModifiers());
}
public function testWithTransformerWithClosure(): void
{
$patch = new Patch();
$transformer = function (array $statements) {
return $statements;
};
$new = $patch->withTransformer($transformer);
$this->assertNotSame($patch, $new);
$this->assertEmpty($patch->getModifiers());
$this->assertEquals([$transformer], $new->getModifiers());
}
public function testWithTransformerWithTransformer(): void
{
$patch = new Patch();
$transformer = new class () implements Patch\Transformer {
public function transform(array $ast): array
{
return $ast;
}
};
$new = $patch->withTransformer($transformer);
$this->assertNotSame($patch, $new);
$this->assertEmpty($patch->getModifiers());
$this->assertEquals([$transformer], $new->getModifiers());
}
public function testWithTransformerMultiple(): void
{
$transformer1 = new class () implements Patch\Transformer {
public function transform(array $ast): array
{
return $ast;
}
};
$transformer2 = function (array $statements) {
return $statements;
};
$patch = new Patch();
$new = $patch
->withTransformer($transformer1)
->withTransformer($transformer2);
$this->assertNotSame($patch, $new);
$this->assertEmpty($patch->getModifiers());
$this->assertEquals([$transformer1, $transformer2], $new->getModifiers());
}
}