* @copyright Meritoo * * @internal * @covers \Meritoo\Common\Utilities\Composer */ class ComposerTest extends BaseTestCase { /** * Path of existing composer.json used as source of data for tests * * @var string */ private $composerJsonPath; /** * Provides names and values of existing nodes * * @return Generator */ public function getExistingNode(): Generator { yield [ 'name', 'test/test', ]; yield [ 'version', '1.0.2', ]; } public function testConstructor() { static::assertHasNoConstructor(Composer::class); } /** * @param string $nodeName Name of existing node * @param string $nodeValue Value of existing node * * @dataProvider getExistingNode */ public function testGetValueExistingNode(string $nodeName, string $nodeValue): void { self::assertEquals($nodeValue, Composer::getValue($this->composerJsonPath, $nodeName)); } public function testGetValueNotExistingComposerJson(): void { self::assertNull(Composer::getValue('', '')); self::assertNull(Composer::getValue('not/existing/composer.json', '')); } public function testGetValueNotExistingNode(): void { self::assertNull(Composer::getValue($this->composerJsonPath, '')); self::assertNull(Composer::getValue($this->composerJsonPath, 'not_existing_node')); } /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->composerJsonPath = $this->getFilePathForTesting(Composer::FILE_NAME_MAIN); } }