Passed
Pull Request — master (#1)
by Kevin
02:39
created

ModelFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
c 2
b 0
f 1
dl 0
loc 37
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A can_instantiate() 0 3 1
A can_instantiate_many() 0 6 1
A can_set_state_via_new() 0 4 1
A can_set_states_with_method() 0 4 1
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