File: FeaturesTest.php

package info (click to toggle)
php-nesbot-carbon 2.73.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,884 kB
  • sloc: php: 158,586; xml: 99; makefile: 33; sh: 14
file content (73 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php

declare(strict_types=1);

/**
 * This file is part of the Carbon package.
 *
 * (c) Brian Nesbitt <brian@nesbot.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tests\PHPStan;

use RuntimeException;
use Tests\AbstractTestCase;

class FeaturesTest extends AbstractTestCase
{
    /**
     * @SuppressWarnings(PHPMD.LongVariable)
     */
    protected $phpStanPreviousDirectory = '.';

    protected function setUp(): void
    {
        parent::setUp();
        $this->phpStanPreviousDirectory = getcwd();
        chdir(__DIR__.'/../..');
    }

    protected function tearDown(): void
    {
        chdir($this->phpStanPreviousDirectory);
        parent::tearDown();
    }

    public function testAnalysesWithoutErrors(): void
    {
        $this->assertStringContainsString(
            '[OK] No errors',
            $this->analyze(__DIR__.'/project.neon')
        );
    }

    public function testAnalysesWithAnError(): void
    {
        $this->assertStringContainsString(
            '22     Static call to instance method Carbon\Carbon::foo().',
            $this->analyze(__DIR__.'/bad-project.neon')
        );
    }

    private function analyze(string $file): string
    {
        $output = shell_exec(implode(' ', [
            implode(DIRECTORY_SEPARATOR, ['.', 'vendor', 'bin', 'phpstan']),
            'analyse',
            '--configuration='.escapeshellarg(realpath($file)),
            '--no-progress',
            '--no-interaction',
            '--level=0',
            escapeshellarg(realpath(__DIR__.'/Fixture.php')),
        ]));

        if (!\is_string($output)) {
            throw new RuntimeException('Executing phpstan returned '.var_export($output, true));
        }

        return $output;
    }
}