Skip to content

Commit 3517c59

Browse files
committed
feat(ci): fix test to not depend on directory
1 parent ad030c1 commit 3517c59

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

.github/workflows/tests-multiples-versions.yml renamed to .github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHP Composer
1+
name: CI
22

33
on:
44
push:
@@ -36,4 +36,5 @@ jobs:
3636
run: composer validate
3737

3838
- name: Run test suite
39-
run: composer test
39+
run:
40+
composer test

tests/Units/DependencyInjection/ContainerBuilderTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@
1919
final class ContainerBuilderTest extends TestCase
2020
{
2121
private ContainerBuilder $containerBuilder;
22-
private string $rootPath = '/code';
2322
private string $rootNamespace = 'Tests\\Shared\\Infrastructure\\';
24-
private string $containerCachePath = '/code/tmp/cache/container';
2523
private string $containerCacheFileName = 'CompiledContainer.php';
24+
private string $containerCachePath;
2625
private string $containerCacheFilePath;
2726

2827
public function setUp(): void
2928
{
29+
$rootPath = dirname(__DIR__, 3);
30+
$this->containerCachePath = "$rootPath/tmp/cache/container";
3031
$this->containerCacheFilePath = "$this->containerCachePath/$this->containerCacheFileName";
3132

3233
$this->removeContainerCache();
3334

3435
$this->containerBuilder = ContainerBuilder::create()
3536
->addRootNamespace($this->rootNamespace)
36-
->addRootPath($this->rootPath);
37+
->addRootPath($rootPath);
3738
}
3839

3940
public function tearDown(): void

tests/Units/DependencyInjection/ContainerFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ final class ContainerFactoryTest extends TestCase
1818
{
1919
private string $settingsPath;
2020
private ContainerInterface $container;
21-
private string $containerCachePath = '/code/tmp/cache/container';
22-
private string $containerCacheFileName = 'CompiledContainer.php';
21+
private string $containerCachePath;
2322
private string $containerCacheFilePath;
23+
private string $containerCacheFileName = 'CompiledContainer.php';
2424

2525
/**
2626
* @throws Exception
2727
*/
2828
public function setUp(): void
2929
{
30+
$rootPath = dirname(__DIR__, 3);
31+
$this->containerCachePath = "$rootPath/tmp/cache/container";
3032
$this->containerCacheFilePath = "$this->containerCachePath/$this->containerCacheFileName";
3133
$this->removeContainerCache();
3234

tests/Units/Resolver/ResolverCacheTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public function setUp(): void
1919

2020
$file = 'example_cache.php';
2121

22-
$this->dir = '/code/tmp/cache/container/resolved_classes';
23-
$this->pathCacheFile = $this->dir . '/' . $file;
22+
$rootPath = dirname(__DIR__, 3);
23+
$this->dir = "$rootPath/tmp/cache/container/resolved_classes";
24+
$this->pathCacheFile = "$this->dir/$file";
2425

2526
@unlink($this->pathCacheFile);
2627
@rmdir($this->dir);

tests/Units/Resolver/ResolverTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414

1515
final class ResolverTest extends TestCase
1616
{
17-
private string $rootDirectory = '/code';
17+
private string $rootPath;
18+
private string $resolverCacheDir;
19+
private string $resolverCachePathFile;
1820
private string $rootNamespace = 'Tests\\Shared\\Infrastructure\\';
19-
private string $resolverCacheDir = '/code/tmp/cache/container/resolved_classes';
2021
private string $resolverFileName = 'example_cache.php';
21-
private string $resolverCachePathFile;
2222

2323
public function setUp(): void
2424
{
2525
parent::setUp();
2626

27+
$this->rootPath = dirname(__DIR__, 3);
28+
$this->resolverCacheDir = "$this->rootPath/tmp/cache/container/resolved_classes";
2729
$this->resolverCachePathFile = "$this->resolverCacheDir/$this->resolverFileName";
2830

2931
$this->removeCacheFolder();
@@ -56,10 +58,10 @@ public function it_should_can_resolve_interfaces(): void
5658
Types::INTERFACE,
5759
'tests',
5860
$this->rootNamespace,
59-
$this->rootDirectory
61+
$this->rootPath
6062
);
6163

62-
$this->assertEquals([ExampleImplement::class, Example::class], $actual);
64+
$this->assertEqualsCanonicalizing([Example::class, ExampleImplement::class], $actual);
6365
}
6466

6567
/**
@@ -76,7 +78,7 @@ public function it_should_can_resolve_interfaces_cache(): void
7678
Types::INTERFACE,
7779
'tests',
7880
$this->rootNamespace,
79-
$this->rootDirectory,
81+
$this->rootPath,
8082
$this->resolverCachePathFile
8183
);
8284

@@ -85,11 +87,11 @@ public function it_should_can_resolve_interfaces_cache(): void
8587
Types::INTERFACE,
8688
'tests',
8789
$this->rootNamespace,
88-
$this->rootDirectory,
90+
$this->rootPath,
8991
$this->resolverCachePathFile
9092
);
9193

92-
$this->assertEquals([ExampleImplement::class, Example::class], $actual);
94+
$this->assertEqualsCanonicalizing([Example::class, ExampleImplement::class], $actual);
9395
}
9496

9597
/**
@@ -106,9 +108,9 @@ public function it_should_can_resolve_attributes(): void
106108
Types::ATTRIBUTE,
107109
'tests',
108110
$this->rootNamespace,
109-
$this->rootDirectory
111+
$this->rootPath
110112
);
111113

112-
$this->assertEquals([ExampleWithAttribute::class], $actual);
114+
$this->assertEqualsCanonicalizing([ExampleWithAttribute::class], $actual);
113115
}
114116
}

0 commit comments

Comments
 (0)