|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
6
|
|
|
use Zenstruck\Foundry\Test\Factories; |
|
7
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Kevin Bond <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
final class ModelFactoryTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
use Factories; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @test |
|
18
|
|
|
*/ |
|
19
|
|
|
public function can_set_states_with_method(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->assertFalse(PostFactory::createOne()->isPublished()); |
|
|
|
|
|
|
22
|
|
|
$this->assertTrue(PostFactory::new()->published()->create()->isPublished()); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @test |
|
27
|
|
|
*/ |
|
28
|
|
|
public function can_set_state_via_new(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertFalse(PostFactory::createOne()->isPublished()); |
|
31
|
|
|
$this->assertTrue(PostFactory::new('published')->create()->isPublished()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @test |
|
36
|
|
|
*/ |
|
37
|
|
|
public function can_instantiate(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertSame('title', PostFactory::new()->create(['title' => 'title'])->getTitle()); |
|
|
|
|
|
|
40
|
|
|
$this->assertSame('title', PostFactory::createOne(['title' => 'title'])->getTitle()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
* @group legacy |
|
46
|
|
|
*/ |
|
47
|
|
|
public function can_instantiate_many_legacy(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$objects = PostFactory::createMany(2, ['title' => 'title']); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertCount(2, $objects); |
|
52
|
|
|
$this->assertSame('title', $objects[0]->getTitle()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
*/ |
|
58
|
|
|
public function can_instantiate_many(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$objects = PostFactory::createMany(2, ['title' => 'title']); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertCount(2, $objects); |
|
63
|
|
|
$this->assertSame('title', $objects[0]->getTitle()); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths