Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
name: 'Composer Validate'
run: composer validate --ansi

-
name: 'Rector'
run: composer rector --ansi

-
name: 'Coding Standard'
run: composer fix-cs --ansi
Expand Down
4 changes: 3 additions & 1 deletion src/Analyzer/UnusedDefinitionsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\SplFileInfo;

/**
* @see \Rector\Behastan\Tests\Analyzer\UnusedDefinitionsAnalyzer\UnusedDefinitionsAnalyzerTest
*/
final readonly class UnusedDefinitionsAnalyzer
{
/**
Expand Down Expand Up @@ -43,7 +46,6 @@ public function analyse(array $contextFiles, array $featureFiles): array
$this->maskCollectionStatsPrinter->printStats($maskCollection);

$featureInstructions = $this->usedInstructionResolver->resolveInstructionsFromFeatureFiles($featureFiles);

$maskProgressBar = $this->symfonyStyle->createProgressBar($maskCollection->count());

$unusedMasks = [];
Expand Down
8 changes: 7 additions & 1 deletion src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public function create(): Container
return $phpParserFactory->createForHostVersion();
});

// silence in PHPUnit tests to keep output clear
$consoleOutput = new ConsoleOutput();
$consoleOutput->setVerbosity(
defined('PHPUNIT_COMPOSER_INSTALL') ? ConsoleOutput::VERBOSITY_QUIET : ConsoleOutput::VERBOSITY_NORMAL
);

$container->singleton(
SymfonyStyle::class,
static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())
static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), $consoleOutput)
);

return $container;
Expand Down
9 changes: 9 additions & 0 deletions stubs/Behat/Behat/Context/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Behat\Behat\Context;

interface Context
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Analyzer\UnusedDefinitionsAnalyzer\Fixture\Contexts;

use Behat\Behat\Context\Context;
use Behat\Step\Given;
use Behat\Step\When;

final class LoginContext implements Context
{
#[Given('I am on the login page')]
public function iAmOnTheLoginPage(): void
{
// open login page
}

#[When('I login as :username')]
public function iLoginAs(string $username): void
{
// fill credentials and submit form
}

#[When('The :username is logged in')]
public function isLoggedIn(string $username): void
{
// fill credentials and submit form
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: User login
Scenario: Successful login
Given I am on the login page
When I login as "Tomas"
Then The "Tomas" is logged in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Rector\Behastan\Tests\Analyzer\UnusedDefinitionsAnalyzer;

use Rector\Behastan\Analyzer\UnusedDefinitionsAnalyzer;
use Rector\Behastan\Finder\BehatMetafilesFinder;
use Rector\Behastan\Tests\AbstractTestCase;

final class UnusedDefinitionsAnalyzerTest extends AbstractTestCase
{
private UnusedDefinitionsAnalyzer $unusedDefinitionsAnalyzer;

protected function setUp(): void
{
parent::setUp();

$this->unusedDefinitionsAnalyzer = $this->make(UnusedDefinitionsAnalyzer::class);
}

public function test(): void
{
$featureFiles = BehatMetafilesFinder::findFeatureFiles([__DIR__ . '/Fixture/Features']);
$this->assertCount(1, $featureFiles);

$contextFiles = BehatMetafilesFinder::findContextFiles([__DIR__ . '/Fixture/Contexts']);
$this->assertCount(1, $contextFiles);

$unusedDefinitions = $this->unusedDefinitionsAnalyzer->analyse($contextFiles, $featureFiles);

$this->assertCount(0, $unusedDefinitions);
}
}