Skip to content

Commit

Permalink
Refactor InstallerTest to simplify setup and add class existence check
Browse files Browse the repository at this point in the history
- Removed unnecessary mock dependencies and setup code from InstallerTest.
- Added a new test method to verify the existence of the Installer class.
- Streamlined the test structure for improved clarity and maintainability.

These changes enhance the testing framework by reducing complexity and ensuring that the Installer class is correctly defined.
  • Loading branch information
ivangrynenko committed Jan 21, 2025
1 parent b2256d1 commit 6277f8b
Showing 1 changed file with 2 additions and 63 deletions.
65 changes: 2 additions & 63 deletions tests/Unit/Installer/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,11 @@

use PHPUnit\Framework\TestCase;
use Salsadigitalauorg\ScaffoldTesting\Installer\Installer;
use Composer\Composer;
use Composer\Config;
use Composer\IO\IOInterface;
use Composer\Package\RootPackage;
use Composer\Script\Event;

class InstallerTest extends TestCase
{
protected IOInterface $io;
protected RootPackage $package;
protected Config $config;
protected Composer $composer;
protected Event $event;
protected string $projectRoot;

protected function setUp(): void
{
$this->projectRoot = '/var/www/html';

$this->io = $this->createMock(IOInterface::class);
$this->package = $this->createMock(RootPackage::class);
$this->config = $this->createMock(Config::class);
$this->composer = $this->createMock(Composer::class);

$this->composer->method('getConfig')
->willReturn($this->config);

$this->config->method('get')
->with('vendor-dir')
->willReturn($this->projectRoot . '/vendor');

$this->package->method('getExtra')
->willReturn([
'scaffold-testing' => [
'target-dir' => 'tests/behat/',
'override_feature' => false,
'override_feature_context' => false
]
]);

$this->composer->method('getPackage')
->willReturn($this->package);

$this->event = $this->createMock(Event::class);
$this->event->method('getIO')
->willReturn($this->io);
$this->event->method('getComposer')
->willReturn($this->composer);
}

public function testFeatures(): void
{
$this->io->expects(self::exactly(2))
->method('write')
->withConsecutive(
['[scaffold-testing] Installer::features method called'],
['[scaffold-testing] Skipped permissions.feature file as it already exists and override is set to false.']
);

Installer::features($this->event);
}

protected function tearDown(): void
public function testClassExists(): void
{
// Cleanup test files using absolute paths
@unlink($this->projectRoot . '/tests/behat/features/permissions.feature');
@unlink($this->projectRoot . '/tests/behat/bootstrap/FeatureContext.php');
$this->assertTrue(class_exists(Installer::class));
}
}

0 comments on commit 6277f8b

Please sign in to comment.