Skip to content

Commit e04b204

Browse files
committed
Add tests for ComposerFinder and ComposerLoader
1 parent 2cd36d5 commit e04b204

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/Domain/ComposerFinderTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Domain;
6+
7+
use NunoMaduro\PhpInsights\Domain\Collector;
8+
use NunoMaduro\PhpInsights\Domain\ComposerFinder;
9+
use NunoMaduro\PhpInsights\Domain\Exceptions\ComposerNotFound;
10+
use PHPUnit\Framework\TestCase;
11+
12+
final class ComposerFinderTest extends TestCase
13+
{
14+
public function testGetComposerPath(): void
15+
{
16+
$collector = new Collector(__DIR__ . '/Insights/Composer/Fixtures/Valid');
17+
$path = ComposerFinder::getPath($collector);
18+
19+
self::assertEquals(
20+
__DIR__ . '/Insights/Composer/Fixtures/Valid/composer.json',
21+
$path
22+
);
23+
}
24+
25+
public function testGetComposerPathThrowExceptionIfNoComposerJsonExist(): void
26+
{
27+
self::expectException(ComposerNotFound::class);
28+
29+
$collector = new Collector(__DIR__ . '/Insights/Composer/Fixtures');
30+
ComposerFinder::getPath($collector);
31+
}
32+
}

tests/Domain/ComposerLoaderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Domain;
6+
7+
use Composer\Composer;
8+
use NunoMaduro\PhpInsights\Domain\Collector;
9+
use NunoMaduro\PhpInsights\Domain\ComposerLoader;
10+
use NunoMaduro\PhpInsights\Domain\Exceptions\ComposerNotFound;
11+
use PHPUnit\Framework\TestCase;
12+
13+
final class ComposerLoaderTest extends TestCase
14+
{
15+
public function testGetInstance(): void
16+
{
17+
$collector = new Collector(__DIR__ . '/Insights/Composer/Fixtures/Valid');
18+
$composer = ComposerLoader::getInstance($collector);
19+
20+
self::assertEquals(Composer::class, get_class($composer));
21+
}
22+
23+
public function testGetExceptionOnFolderWithoutComposerJson(): void
24+
{
25+
self::expectException(ComposerNotFound::class);
26+
27+
$collector = new Collector(__DIR__ . '/Insights/Composer/Fixtures');
28+
ComposerLoader::getInstance($collector);
29+
}
30+
}

0 commit comments

Comments
 (0)