Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed May 17, 2024
1 parent 8a69d92 commit e2eba69
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 deletions.
45 changes: 26 additions & 19 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false"
backupStaticAttributes="false" colors="true" verbose="false" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false"
stopOnFailure="false" stopOnError="false" stderr="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>tests/src</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
stderr="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Test Suite">
<directory>tests/src</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
</php>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
19 changes: 18 additions & 1 deletion src/Commands/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public function perform(
foreach ($workflows as $workflow) {
$table->addRow([
\sprintf('<fg=green>%s</>', $workflow['name']),
$workflow['class'] . "\n" . \sprintf('<fg=blue>%s</>', \str_replace($rootDir, '', $workflow['file'])),
$workflow['class'] . "\n" . \sprintf(
'<fg=blue>%s</>',
self::normalizePath($rootDir, $workflow['file']),
),
$workflow['task_queue'],
]);
}
Expand Down Expand Up @@ -100,4 +103,18 @@ public function perform(

return self::SUCCESS;
}

/**
* @param non-empty-string $rootDir
* @param non-empty-string $file
*/
private static function normalizePath(string $rootDir, string $file): string
{
$file = \str_replace('\\', '/', $file);
$rootDir = \str_replace('\\', '/', $rootDir);

return \str_starts_with($file, $rootDir)
? \substr($file, \strlen($rootDir))
: $file;
}
}
4 changes: 2 additions & 2 deletions tests/src/Commands/InfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testInfo(): void
{
$result = $this->runCommand('temporal:info');

$this->assertSame(
$this->assertStringEqualsStringIgnoringLineEndings(
<<<'OUTPUT'
Workflows
Expand All @@ -57,7 +57,7 @@ public function testInfoWithActivities(): void
'--show-activities' => true,
]);

$this->assertSame(
$this->assertStringEqualsStringIgnoringLineEndings(
<<<'OUTPUT'
Workflows
Expand Down
29 changes: 11 additions & 18 deletions tests/src/DeclarationLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ protected function setUp(): void
{
parent::setUp();

$this->locator = new DeclarationLocator(
$this->classes = m::mock(ClassesInterface::class),
new AttributeReader()
);
$this->locator = new DeclarationLocator(new AttributeReader());
}

public function testEnumClassesShouldBeSkipped(): void
{
$this->classes->shouldReceive('getClasses')->once()->andReturn([
new \ReflectionClass(TestEnum::class),
new \ReflectionClass(TestAbstractClass::class),
new \ReflectionClass(TestInterface::class),
]);
$this->locator->listen(new \ReflectionClass(TestEnum::class));
$this->locator->listen(new \ReflectionClass(TestAbstractClass::class));
$this->locator->listen(new \ReflectionClass(TestInterface::class));

$result = [];

Expand All @@ -45,15 +40,13 @@ public function testEnumClassesShouldBeSkipped(): void

public function testWorkflowsShouldBeRegistered(): void
{
$this->classes->shouldReceive('getClasses')->once()->andReturn([
new \ReflectionClass(TestEnum::class),
new \ReflectionClass(TestAbstractClass::class),
new \ReflectionClass(TestInterface::class),
$workflow1 = new \ReflectionClass(TestWorkflowClass::class),
$workflow2 = new \ReflectionClass(TestWorkflowClassWithInterface::class),
$activity1 = new \ReflectionClass(TestActivityClass::class),
$activity2 = new \ReflectionClass(TestActivityClassWithInterface::class),
]);
$this->locator->listen(new \ReflectionClass(TestEnum::class));
$this->locator->listen(new \ReflectionClass(TestAbstractClass::class));
$this->locator->listen(new \ReflectionClass(TestInterface::class));
$this->locator->listen($workflow1 = new \ReflectionClass(TestWorkflowClass::class));
$this->locator->listen($workflow2 = new \ReflectionClass(TestWorkflowClassWithInterface::class));
$this->locator->listen($activity1 = new \ReflectionClass(TestActivityClass::class));
$this->locator->listen($activity2 = new \ReflectionClass(TestActivityClassWithInterface::class));

$result = [];

Expand Down

0 comments on commit e2eba69

Please sign in to comment.