Passed
Pull Request — master (#111)
by Wouter
02:00
created

ModelFactoryTest::can_instantiate_many()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Unit;
4
5
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method isPublished() does not exist on Zenstruck\Foundry\Proxy. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $this->assertFalse(PostFactory::createOne()->/** @scrutinizer ignore-call */ isPublished());
Loading history...
22
        $this->assertTrue(PostFactory::new()->published()->create()->isPublished());
0 ignored issues
show
Bug introduced by
The method published() does not exist on Zenstruck\Foundry\ModelFactory. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $this->assertTrue(PostFactory::new()->/** @scrutinizer ignore-call */ published()->create()->isPublished());
Loading history...
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());
0 ignored issues
show
Bug introduced by
The method getTitle() does not exist on Zenstruck\Foundry\Proxy. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $this->assertSame('title', PostFactory::new()->create(['title' => 'title'])->/** @scrutinizer ignore-call */ getTitle());
Loading history...
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