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

CustomFactoryTest::can_instantiate_many()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
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