• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Laravel/Tests/Console/Maker/MakeStateProcessorCommandTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Laravel\Tests\Console\Maker;
15

16
use ApiPlatform\Laravel\Tests\Console\Maker\Utils\AppServiceFileGenerator;
17
use ApiPlatform\Laravel\Tests\Console\Maker\Utils\PathResolver;
18
use Illuminate\Console\Command;
19
use Illuminate\Contracts\Filesystem\FileNotFoundException;
20
use Illuminate\Filesystem\Filesystem;
21
use Orchestra\Testbench\Concerns\WithWorkbench;
22
use Orchestra\Testbench\TestCase;
23
use PHPUnit\Framework\Attributes\DataProvider;
24

25
class MakeStateProcessorCommandTest extends TestCase
26
{
27
    use WithWorkbench;
28

29
    /** @var string */
30
    private const STATE_PROCESSOR_COMMAND = 'make:state-processor';
31
    /** @var string */
32
    private const CHOSEN_CLASS_NAME = 'Choose a class name for your state processor (e.g. <fg=yellow>AwesomeStateProcessor</>)';
33

34
    private Filesystem $filesystem;
35
    private PathResolver $pathResolver;
36
    private AppServiceFileGenerator $appServiceFileGenerator;
37

38
    /**
39
     * @throws FileNotFoundException
40
     */
41
    protected function setup(): void
42
    {
UNCOV
43
        parent::setUp();
×
44

45
        $this->filesystem = new Filesystem();
×
46
        $this->pathResolver = new PathResolver();
×
UNCOV
47
        $this->appServiceFileGenerator = new AppServiceFileGenerator($this->filesystem);
×
48

UNCOV
49
        $this->appServiceFileGenerator->regenerateProviderFile();
×
50
    }
51

52
    /**
53
     * @throws FileNotFoundException
54
     */
55
    public function testMakeStateProviderCommand(): void
56
    {
57
        $processorName = 'MyStateProcessor';
×
58
        $filePath = $this->pathResolver->generateStateFilename($processorName);
×
UNCOV
59
        $appServiceProviderPath = $this->pathResolver->getServiceProviderFilePath();
×
60

61
        $this->artisan(self::STATE_PROCESSOR_COMMAND)
×
62
            ->expectsQuestion(self::CHOSEN_CLASS_NAME, $processorName)
×
63
            ->expectsOutputToContain('Success!')
×
64
            ->expectsOutputToContain("created: $filePath")
×
65
            ->expectsOutputToContain('Next: Open your new State Processor class and start customizing it.')
×
UNCOV
66
            ->assertExitCode(Command::SUCCESS);
×
67

UNCOV
68
        $this->assertFileExists($filePath);
×
69

70
        $appServiceProviderContent = $this->filesystem->get($appServiceProviderPath);
×
71
        $this->assertStringContainsString('use ApiPlatform\State\ProcessorInterface;', $appServiceProviderContent);
×
72
        $this->assertStringContainsString("use App\State\\$processorName;", $appServiceProviderContent);
×
UNCOV
73
        $this->assertStringContainsString('$this->app->tag(MyStateProcessor::class, ProcessorInterface::class);', $appServiceProviderContent);
×
74

UNCOV
75
        $this->filesystem->delete($filePath);
×
76
    }
77

78
    public function testWhenStateProviderClassAlreadyExists(): void
79
    {
80
        $processorName = 'ExistingProcessor';
×
81
        $existingFile = $this->pathResolver->generateStateFilename($processorName);
×
UNCOV
82
        $this->filesystem->put($existingFile, '<?php // Existing processor');
×
83

UNCOV
84
        $expectedError = \sprintf('[ERROR] The file "%s" can\'t be generated because it already exists.', $existingFile);
×
85

86
        $this->artisan(self::STATE_PROCESSOR_COMMAND)
×
87
            ->expectsQuestion(self::CHOSEN_CLASS_NAME, $processorName)
×
88
            ->expectsOutput($expectedError)
×
UNCOV
89
            ->assertExitCode(Command::FAILURE);
×
90

UNCOV
91
        $this->filesystem->delete($existingFile);
×
92
    }
93

94
    #[DataProvider('nullProvider')]
95
    public function testMakeStateFilterCommandWithoutGivenClassName(?string $value): void
96
    {
UNCOV
97
        $this->artisan(self::STATE_PROCESSOR_COMMAND)
×
98
            ->expectsQuestion(self::CHOSEN_CLASS_NAME, $value)
×
99
            ->assertExitCode(Command::FAILURE);
×
100
    }
101

102
    public static function nullProvider(): \Generator
103
    {
104
        yield 'null value used' => ['value' => null];
×
UNCOV
105
        yield 'empty string used' => ['value' => ''];
×
106
    }
107

108
    /**
109
     * @throws FileNotFoundException
110
     */
111
    protected function tearDown(): void
112
    {
UNCOV
113
        parent::tearDown();
×
114

UNCOV
115
        $this->appServiceFileGenerator->regenerateProviderFile();
×
116
    }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc