Passed
Push — master ( 02609a...02cd0c )
by Kevin
04:31
created

StoryTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 4
Metric Value
wmc 11
eloc 23
c 6
b 0
f 4
dl 0
loc 87
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A can_access_managed_proxies_via_magic_call_static() 0 3 1
A setUp() 0 4 2
A can_access_managed_proxies_via_magic_call() 0 3 1
A stories_are_only_loaded_once() 0 9 1
A calling_add_is_deprecated() 0 5 1
A stories_can_be_services() 0 7 2
A service_stories_cannot_be_used_without_the_bundle() 0 10 2
A cannot_access_invalid_object() 0 5 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Functional;
4
5
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
6
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
7
use Zenstruck\Foundry\Test\Factories;
8
use Zenstruck\Foundry\Test\ResetDatabase;
9
use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory;
10
use Zenstruck\Foundry\Tests\Fixtures\Stories\CategoryStory;
11
use Zenstruck\Foundry\Tests\Fixtures\Stories\PostStory;
12
use Zenstruck\Foundry\Tests\Fixtures\Stories\ServiceStory;
13
14
/**
15
 * @author Kevin Bond <[email protected]>
16
 */
17
final class StoryTest extends KernelTestCase
18
{
19
    use ExpectDeprecationTrait, Factories, ResetDatabase;
20
21
    protected function setUp(): void
22
    {
23
        if (false === \getenv('DATABASE_URL')) {
24
            self::markTestSkipped('doctrine/orm not enabled.');
25
        }
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function stories_are_only_loaded_once(): void
32
    {
33
        PostFactory::assert()->empty();
34
35
        PostStory::load();
36
        PostStory::load();
37
        PostStory::load();
38
39
        PostFactory::assert()->count(4);
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function can_access_managed_proxies_via_magic_call(): void
46
    {
47
        $this->assertSame('php', CategoryStory::load()->php()->getName());
0 ignored issues
show
Bug introduced by
The method getName() 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

47
        $this->assertSame('php', CategoryStory::load()->php()->/** @scrutinizer ignore-call */ getName());
Loading history...
Bug introduced by
The method php() does not exist on Zenstruck\Foundry\Story. 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

47
        $this->assertSame('php', CategoryStory::load()->/** @scrutinizer ignore-call */ php()->getName());
Loading history...
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function can_access_managed_proxies_via_magic_call_static(): void
54
    {
55
        $this->assertSame('php', CategoryStory::php()->getName());
0 ignored issues
show
Bug introduced by
The method php() does not exist on Zenstruck\Foundry\Tests\...s\Stories\CategoryStory. Since you implemented __callStatic, 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

55
        $this->assertSame('php', CategoryStory::/** @scrutinizer ignore-call */ php()->getName());
Loading history...
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function cannot_access_invalid_object(): void
62
    {
63
        $this->expectException(\InvalidArgumentException::class);
64
65
        CategoryStory::load()->get('invalid');
66
    }
67
68
    /**
69
     * @test
70
     */
71
    public function stories_can_be_services(): void
72
    {
73
        if (!\getenv('USE_FOUNDRY_BUNDLE')) {
74
            $this->markTestSkipped('Stories cannot be services without the foundry bundle.');
75
        }
76
77
        $this->assertSame('From Service', ServiceStory::post()->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

77
        $this->assertSame('From Service', ServiceStory::post()->/** @scrutinizer ignore-call */ getTitle());
Loading history...
Bug introduced by
The method post() does not exist on Zenstruck\Foundry\Tests\...es\Stories\ServiceStory. Since you implemented __callStatic, 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

77
        $this->assertSame('From Service', ServiceStory::/** @scrutinizer ignore-call */ post()->getTitle());
Loading history...
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function service_stories_cannot_be_used_without_the_bundle(): void
84
    {
85
        if (\getenv('USE_FOUNDRY_BUNDLE')) {
86
            $this->markTestSkipped('ZenstruckFoundryBundle enabled.');
87
        }
88
89
        $this->expectException(\RuntimeException::class);
90
        $this->expectExceptionMessage('Stories with dependencies (Story services) cannot be used without the foundry bundle.');
91
92
        ServiceStory::load();
93
    }
94
95
    /**
96
     * @test
97
     * @group legacy
98
     */
99
    public function calling_add_is_deprecated(): void
100
    {
101
        $this->expectDeprecation('Since zenstruck\foundry 1.17.0: Using Story::add() is deprecated, use Story::addState().');
102
103
        CategoryStory::load()->add('foo', 'bar');
104
    }
105
}
106