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
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
level: 8

paths:
- bin
- src
- tests

Expand Down
12 changes: 12 additions & 0 deletions src/Analyzer/UnusedDefinitionsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Rector\Behastan\ValueObject\Mask\SkippedMask;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\SplFileInfo;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Behastan\Tests\Analyzer\UnusedDefinitionsAnalyzer\UnusedDefinitionsAnalyzerTest
Expand Down Expand Up @@ -42,7 +43,18 @@ public function __construct(
*/
public function analyse(array $contextFiles, array $featureFiles): array
{
Assert::allIsInstanceOf($contextFiles, SplFileInfo::class);
foreach ($contextFiles as $contextFile) {
Assert::endsWith($contextFile->getFilename(), '.php');
}

Assert::allIsInstanceOf($featureFiles, SplFileInfo::class);
foreach ($featureFiles as $featureFile) {
Assert::endsWith($featureFile->getFilename(), '.feature');
}

$maskCollection = $this->definitionMasksResolver->resolve($contextFiles);

$this->maskCollectionStatsPrinter->printStats($maskCollection);

$featureInstructions = $this->usedInstructionResolver->resolveInstructionsFromFeatureFiles($featureFiles);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Analyzer\UnusedDefinitionsAnalyzer\Fixture\Contexts;
namespace Rector\Behastan\Tests\Analyzer\UnusedDefinitionsAnalyzer\Fixture\EverythingUsed;

use Behat\Behat\Context\Context;
use Behat\Step\Given;
Expand All @@ -11,18 +11,20 @@ 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('I login with :email email')]
public function iLoginWith(string $email): void
{
}

#[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
Expand Up @@ -2,4 +2,5 @@ Feature: User login
Scenario: Successful login
Given I am on the login page
When I login as "Tomas"
When I login with "tomas.me@gmail.com" email
Then The "Tomas" is logged in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\Behastan\Tests\Fixture;
namespace Rector\Behastan\Tests\Analyzer\UnusedDefinitionsAnalyzer\Fixture\UnusedMasks;

final class BehatContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rector\Behastan\Analyzer\UnusedDefinitionsAnalyzer;
use Rector\Behastan\Finder\BehatMetafilesFinder;
use Rector\Behastan\Tests\AbstractTestCase;
use Rector\Behastan\ValueObject\Mask\AbstractMask;

final class UnusedDefinitionsAnalyzerTest extends AbstractTestCase
{
Expand All @@ -19,16 +20,34 @@ protected function setUp(): void
$this->unusedDefinitionsAnalyzer = $this->make(UnusedDefinitionsAnalyzer::class);
}

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

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

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

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

public function testFoundMask(): void
{
$featureFiles = BehatMetafilesFinder::findFeatureFiles([__DIR__ . '/Fixture/UnusedMasks']);
$contextFiles = BehatMetafilesFinder::findContextFiles([__DIR__ . '/Fixture/UnusedMasks']);

$this->assertCount(1, $featureFiles);
$this->assertCount(1, $contextFiles);

$unusedMasks = $this->unusedDefinitionsAnalyzer->analyse($contextFiles, $featureFiles);
$this->assertCount(1, $unusedMasks);
$this->assertContainsOnlyInstancesOf(AbstractMask::class, $unusedMasks);

/** @var AbstractMask $unusedMask */
$unusedMask = $unusedMasks[0];
$this->assertSame(__DIR__ . '/Fixture/UnusedMasks/BehatContext.php', $unusedMask->filePath);
$this->assertSame('never used', $unusedMask->mask);
}
}
48 changes: 0 additions & 48 deletions tests/BehastanTest.php

This file was deleted.