-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-writes DefaultStrategy and adds unit tests
- Loading branch information
Showing
3 changed files
with
156 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* This file is part of the BoxManifest package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Bartlett\BoxManifest\Tests; | ||
|
||
use Bartlett\BoxManifest\Composer\DefaultStrategy; | ||
use Bartlett\BoxManifest\Composer\ManifestFactory; | ||
|
||
use KevinGH\Box\Configuration\Configuration; | ||
|
||
use stdClass; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* Unit tests for DefaultStrategy component of the Box Manifest | ||
* | ||
* @author Laurent Laville | ||
* @since Release 4.0.0 | ||
*/ | ||
final class DefaultStrategyTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider dpRecognizedFilePatterns | ||
*/ | ||
public function testRecognizedFilePatterns(string $outputFormat, ?string $resource, bool $expectedException): void | ||
{ | ||
$this->testAutoDetection($outputFormat, $resource, $expectedException); | ||
} | ||
|
||
/** | ||
* @dataProvider dpRecognizedOutputFormat | ||
*/ | ||
public function testRecognizedOutputFormat(string $outputFormat, ?string $resource, bool $expectedException): void | ||
{ | ||
$this->testAutoDetection($outputFormat, $resource, $expectedException); | ||
} | ||
|
||
private function testAutoDetection(string $outputFormat, ?string $resource, bool $expectedException): void | ||
{ | ||
if ($expectedException) { | ||
$this->expectException(InvalidArgumentException::class); | ||
} | ||
|
||
$configFilePath = __DIR__ . '/../fixtures/phario-manifest-2.0.x-dev/box.json'; | ||
|
||
$raw = new stdClass(); | ||
$main = 'main'; | ||
$raw->{$main} = false; | ||
$config = Configuration::create($configFilePath, $raw); | ||
|
||
$factory = new ManifestFactory($config, true, '4.x-dev', '4.x-dev'); | ||
$strategy = new DefaultStrategy($factory); | ||
|
||
$callable = $strategy->getCallable($outputFormat, $resource); | ||
$this->assertIsCallable($callable); | ||
} | ||
|
||
public static function dpRecognizedFilePatterns(): iterable | ||
{ | ||
yield ['auto', null, false]; | ||
yield ['auto', 'console.txt', false]; | ||
yield ['auto', 'plain.txt', false]; | ||
yield ['auto', 'manifest.txt', false]; | ||
yield ['auto', 'ansi.txt', false]; | ||
yield ['auto', 'sbom.json', false]; | ||
yield ['auto', 'sbom.xml', false]; | ||
yield ['auto', 'sbom.cdx.json', false]; | ||
yield ['auto', 'sbom.cdx.xml', false]; | ||
yield ['auto', 'custom.bin', false]; | ||
yield ['auto', 'custom.txt', true]; | ||
} | ||
|
||
public static function dpRecognizedOutputFormat(): iterable | ||
{ | ||
yield ['console', null, false]; | ||
yield ['console', 'whatever.you.want', false]; | ||
|
||
yield ['plain', null, false]; | ||
yield ['plain', 'whatever.you.want', false]; | ||
|
||
yield ['ansi', null, false]; | ||
yield ['ansi', 'whatever.you.want', false]; | ||
|
||
yield ['sbom-json', null, false]; | ||
yield ['sbom-json', 'whatever.you.want', false]; | ||
|
||
yield ['sbom-xml', null, false]; | ||
yield ['sbom-xml', 'whatever.you.want', false]; | ||
|
||
yield ['\My\Space\ClassNotFound', null, true]; | ||
yield ['\My\Space\ClassNotFound', 'whatever.you.want', true]; | ||
} | ||
} |