Passed
Pull Request — master (#1)
by Kevin
07:49
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 Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory;
6
use Zenstruck\Foundry\Tests\UnitTestCase;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class ModelFactoryTest extends UnitTestCase
12
{
13
    /**
14
     * @test
15
     */
16
    public function can_set_states_with_method(): void
17
    {
18
        $this->assertFalse(PostFactory::new()->withoutPersisting()->create()->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

18
        $this->assertFalse(PostFactory::new()->withoutPersisting()->create()->/** @scrutinizer ignore-call */ isPublished());
Loading history...
19
        $this->assertTrue(PostFactory::new()->published()->withoutPersisting()->create()->isPublished());
0 ignored issues
show
Bug introduced by
The method published() does not exist on Zenstruck\Foundry\ModelFactory. It seems like you code against a sub-type of Zenstruck\Foundry\ModelFactory such as Zenstruck\Foundry\Tests\...s\Factories\PostFactory. ( Ignorable by Annotation )

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

19
        $this->assertTrue(PostFactory::new()->/** @scrutinizer ignore-call */ published()->withoutPersisting()->create()->isPublished());
Loading history...
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function can_set_state_via_new(): void
26
    {
27
        $this->assertFalse(PostFactory::new()->withoutPersisting()->create()->isPublished());
28
        $this->assertTrue(PostFactory::new('published')->withoutPersisting()->create()->isPublished());
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function can_instantiate(): void
35
    {
36
        $this->assertSame('title', PostFactory::new()->withoutPersisting()->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

36
        $this->assertSame('title', PostFactory::new()->withoutPersisting()->create(['title' => 'title'])->/** @scrutinizer ignore-call */ getTitle());
Loading history...
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function can_instantiate_many(): void
43
    {
44
        $objects = PostFactory::new()->withoutPersisting()->createMany(2, ['title' => 'title']);
45
46
        $this->assertCount(2, $objects);
47
        $this->assertSame('title', $objects[0]->getTitle());
48
    }
49
}
50