Passed
Pull Request — master (#1)
by Kevin
03:05
created

CustomFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A can_set_states_with_method() 0 4 1
A can_set_state_via_new() 0 4 1
A can_instantiate() 0 3 1
A can_instantiate_many() 0 6 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Unit;
4
5
use PHPUnit\Framework\TestCase;
6
use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class CustomFactoryTest extends TestCase
12
{
13
    /**
14
     * @test
15
     */
16
    public function can_set_states_with_method(): void
17
    {
18
        $this->assertFalse(PostFactory::new()->instantiate()->isPublished());
19
        $this->assertTrue(PostFactory::new()->published()->instantiate()->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()->instantiate()->isPublished());
Loading history...
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function can_set_state_via_new(): void
26
    {
27
        $this->assertFalse(PostFactory::new()->instantiate()->isPublished());
28
        $this->assertTrue(PostFactory::new('published')->instantiate()->isPublished());
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function can_instantiate(): void
35
    {
36
        $this->assertSame('title', PostFactory::new()->instantiate(['title' => 'title'])->getTitle());
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function can_instantiate_many(): void
43
    {
44
        $objects = PostFactory::new()->instantiateMany(2, ['title' => 'title']);
45
46
        $this->assertCount(2, $objects);
47
        $this->assertSame('title', $objects[0]->getTitle());
48
    }
49
}
50