From d7a35fae0a518522007bf6267a17a828e7b2ce67 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 4 Sep 2019 21:48:07 +0300 Subject: [PATCH 1/3] Pass tests on Windows; Skipped testUnwritableDirInConstructor(), testUnwritableDir() on Windows; --- .../CodeFile/AbstractCodeFile.php | 6 +- src/SchemaGenerator/SchemaClassGenerator.php | 2 +- tests/AbstractCodeFileTest.php | 39 +++++-- tests/ArgumentsObjectClassBuilderTest.php | 50 +++++---- tests/ClassFileTest.php | 106 +++++++++++++++--- tests/ClientTest.php | 2 +- tests/CodeFileTestCase.php | 63 ++++++++++- tests/EnumObjectBuilderTest.php | 26 +++-- tests/InputObjectClassBuilderTest.php | 58 ++++++---- tests/QueryObjectClassBuilderTest.php | 50 +++++---- tests/QueryObjectTest.php | 49 ++++---- tests/SchemaClassGeneratorTest.php | 94 ++++++++++------ tests/TraitFileTest.php | 95 +++++++++++++--- 13 files changed, 460 insertions(+), 180 deletions(-) diff --git a/src/SchemaGenerator/CodeGenerator/CodeFile/AbstractCodeFile.php b/src/SchemaGenerator/CodeGenerator/CodeFile/AbstractCodeFile.php index 9df6494..2033967 100644 --- a/src/SchemaGenerator/CodeGenerator/CodeFile/AbstractCodeFile.php +++ b/src/SchemaGenerator/CodeGenerator/CodeFile/AbstractCodeFile.php @@ -69,8 +69,8 @@ public final function writeFile(): bool $fileContents = $this->generateFileContents(); $filePath = $this->writeDir; - if (substr($filePath, -1) !== '/') { - $filePath .= '/'; + if (substr($filePath, -1) !== DIRECTORY_SEPARATOR) { + $filePath .= DIRECTORY_SEPARATOR; } $filePath .= $this->fileName . '.php'; @@ -138,6 +138,6 @@ public function changeWriteDir(string $writeDir) */ public function getWritePath(): string { - return $this->writeDir . "/$this->fileName.php"; + return $this->writeDir . DIRECTORY_SEPARATOR . $this->fileName . ".php"; } } \ No newline at end of file diff --git a/src/SchemaGenerator/SchemaClassGenerator.php b/src/SchemaGenerator/SchemaClassGenerator.php index 2752bee..26cb809 100644 --- a/src/SchemaGenerator/SchemaClassGenerator.php +++ b/src/SchemaGenerator/SchemaClassGenerator.php @@ -295,7 +295,7 @@ private function setWriteDir(): void $currentDir = dirname($currentDir); } - $this->writeDir = $currentDir . '/schema_object'; + $this->writeDir = $currentDir . DIRECTORY_SEPARATOR .'schema_object'; } /** diff --git a/tests/AbstractCodeFileTest.php b/tests/AbstractCodeFileTest.php index d6c22c1..3d97dca 100644 --- a/tests/AbstractCodeFileTest.php +++ b/tests/AbstractCodeFileTest.php @@ -26,7 +26,7 @@ class AbstractCodeFileTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/abstract_code_files'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'abstract_code_files'; } /** @@ -39,7 +39,7 @@ protected function setUp(): void AbstractCodeFile::class, [static::getGeneratedFilesDir(), $this->fileName] ); - $this->codeFile->method('generateFileContents')->willReturn("codeFile->method('generateFileContents')->willReturn("expectException(\Exception::class); $mock = $this->getMockForAbstractClass( AbstractCodeFile::class, - [static::getGeneratedFilesDir() . '/invalid', $this->fileName] + [static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . 'invalid', $this->fileName] ); - $mock->method('generateFileContents')->willReturn("method('generateFileContents')->willReturn("expectException(\Exception::class); + $mock = $this->getMockForAbstractClass( AbstractCodeFile::class, [$testDir, $this->fileName] ); - $mock->method('generateFileContents')->willReturn("method('generateFileContents')->willReturn("expectException(\Exception::class); - $this->codeFile->changeWriteDir(static::getGeneratedFilesDir() . '/invalid'); + $this->codeFile->changeWriteDir(static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . 'invalid'); } /** * @testdox Test the behavior of changeWriteDir method when provided with a non-writable directory * + * @requires OS ^Windows * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::changeWriteDir * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::validateDirectory */ public function testUnwritableDir() { - $testDir = static::getGeneratedFilesDir() . '/unwritable'; + $testDir = static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR .'unwritable'; mkdir($testDir); chmod($testDir, 0444); @@ -111,7 +116,7 @@ public function testUnwritableDir() */ public function testWritePathGetter() { - $this->assertEquals(static::getGeneratedFilesDir() . "/$this->fileName.php", $this->codeFile->getWritePath()); + $this->assertEquals(static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $this->fileName . ".php", $this->codeFile->getWritePath()); } /** @@ -124,7 +129,13 @@ public function testWritePathGetter() public function testFileWritingWorks() { $this->codeFile->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$this->fileName.php", $this->codeFile->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $this->fileName . ".php", $this->codeFile->getWritePath() + ) + ); + } /** @@ -137,10 +148,14 @@ public function testFileWritingWorks() public function testFileWritingWorksWithTrailingSlash() { $this->fileName = 'EmptyCodeFileWithSlash'; - $this->codeFile->changeWriteDir($this->codeFile->getWriteDir() . '/'); + $this->codeFile->changeWriteDir($this->codeFile->getWriteDir() . DIRECTORY_SEPARATOR); $this->codeFile->changeFileName($this->fileName); $this->codeFile->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$this->fileName.php", $this->codeFile->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $this->fileName . ".php", $this->codeFile->getWritePath() + ) + ); } } \ No newline at end of file diff --git a/tests/ArgumentsObjectClassBuilderTest.php b/tests/ArgumentsObjectClassBuilderTest.php index cecab82..bd3aa13 100644 --- a/tests/ArgumentsObjectClassBuilderTest.php +++ b/tests/ArgumentsObjectClassBuilderTest.php @@ -19,7 +19,7 @@ class ArgumentsObjectClassBuilderTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/arguments_objects'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'arguments_objects'; } /** @@ -38,9 +38,11 @@ public function testAddScalarArgument() $classBuilder->addScalarArgument('scalarProperty'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -61,9 +63,11 @@ public function testAddMultipleScalarArguments() $classBuilder->addScalarArgument('another_scalar_property'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -83,9 +87,11 @@ public function testAddListArgument() $classBuilder->addListArgument('listProperty', 'string'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -106,9 +112,11 @@ public function testAddMultipleListArguments() $classBuilder->addListArgument('another_list_property', 'string'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -128,9 +136,11 @@ public function testAddInputObjectArgument() $classBuilder->addInputObjectArgument('objectProperty', 'Some'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -151,9 +161,11 @@ public function testAddMultipleInputObjectArguments() $classBuilder->addInputObjectArgument('another_object_property', 'Another'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } } \ No newline at end of file diff --git a/tests/ClassFileTest.php b/tests/ClassFileTest.php index da624dc..0d88eb2 100644 --- a/tests/ClassFileTest.php +++ b/tests/ClassFileTest.php @@ -11,7 +11,7 @@ class ClassFileTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/classes'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'classes'; } /** @@ -26,7 +26,11 @@ public function testEmptyClass() $class = new ClassFile(static::getGeneratedFilesDir(), $fileName); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); return $class; } @@ -46,7 +50,11 @@ public function testExtendsClass() $class->extendsClass('Base'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -58,9 +66,13 @@ public function testExtendsEmptyClassName(ClassFile $class) { $class->extendsClass(''); $class->writeFile(); - $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -78,14 +90,22 @@ public function testImplementsInterfaces() $class->implementsInterface('InterfaceOne'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); $fileName = 'ClassImplementsMultipleInterfaces'; $class->changeFileName($fileName); $class->implementsInterface('InterfaceTwo'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); return $class; } @@ -103,7 +123,12 @@ public function testImplementDuplicateInterfaces(ClassFile $class) $class->writeFile(); $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -117,7 +142,12 @@ public function testImplementEmptyInterfaceName(ClassFile $class) $class->writeFile(); $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -135,7 +165,11 @@ public function testUseTraits() $class->addTrait('TraitOne'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); $fileName = 'ClassWithMultipleTraits'; $class->changeFileName($fileName); @@ -143,7 +177,11 @@ public function testUseTraits() $class->addTrait('TraitThree'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); return $class; } @@ -161,7 +199,12 @@ public function testUseDuplicateTraits(ClassFile $class) $class->writeFile(); $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -175,7 +218,12 @@ public function testUseEmptyTraitName(ClassFile $class) $class->writeFile(); $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -194,7 +242,11 @@ public function testClassWithConstants() $class->addConstant('CONST_ONE', 'ONE'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); $fileName = 'ClassWithMultipleConstants'; $class->changeFileName($fileName); @@ -205,7 +257,11 @@ public function testClassWithConstants() $class->addConstant('CONST_SIX', 6.6); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); return $class; } @@ -223,7 +279,12 @@ public function testClassWithDuplicateConstants(ClassFile $class) $class->writeFile(); $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -237,7 +298,12 @@ public function testConstantWithEmptyName(ClassFile $class) $class->writeFile(); $fileName = $class->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } /** @@ -289,6 +355,10 @@ public function testFullClass() }'); $class->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $class->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $class->getWritePath() + ) + ); } } \ No newline at end of file diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 06861f3..ff77a2a 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -63,7 +63,7 @@ public function testConstructClient() /** @var Request $firstRequest */ $firstRequest = $container[0]['request']; - $this->assertEquals('{"query":"query_string"}', $firstRequest->getBody()->getContents()); + $this->assertEquals('{"query":"query_string","variables":{}}', $firstRequest->getBody()->getContents()); /** @var Request $secondRequest */ $secondRequest = $container[1]['request']; diff --git a/tests/CodeFileTestCase.php b/tests/CodeFileTestCase.php index 986fae4..2290f12 100644 --- a/tests/CodeFileTestCase.php +++ b/tests/CodeFileTestCase.php @@ -11,7 +11,7 @@ abstract class CodeFileTestCase extends TestCase */ protected static function getGeneratedFilesDir() { - return dirname(__FILE__) . '/files_generated'; + return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files_generated'; } /** @@ -19,7 +19,8 @@ protected static function getGeneratedFilesDir() */ protected static function getExpectedFilesDir() { - return dirname(__FILE__) . '/files_expected'; + + return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files_expected'; } /** @@ -28,7 +29,10 @@ protected static function getExpectedFilesDir() public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - mkdir(static::getGeneratedFilesDir()); + + if ( !is_dir(static::getGeneratedFilesDir() )) { + mkdir(static::getGeneratedFilesDir()); + } } /** @@ -45,9 +49,10 @@ public static function tearDownAfterClass(): void */ private static function removeDirRecursive($dirName) { + foreach (scandir($dirName) as $fileName) { if ($fileName !== '.' && $fileName !== '..') { - $filePath = "$dirName/$fileName"; + $filePath = $dirName . DIRECTORY_SEPARATOR . $fileName; if (is_dir($filePath)) { static::removeDirRecursive($filePath); } else { @@ -55,6 +60,54 @@ private static function removeDirRecursive($dirName) } } } - rmdir($dirName); + + @rmdir($dirName); + } + + /** + * Read file content ignoring whitespace characters + * @param $filename + * @return string + */ + private function readFileContent($filename) { + + $content = file_get_contents($filename); + + if (!$content) { + return ''; + } + + return str_replace(["\t","\n","\r","\0","\x0B"],'', $content ); } + + /** + * Compare files by content + * @param $expectedFile + * @param $actualFile + * @return bool + */ + public function assertFileEqualsIgnoreWhitespace($expectedFile, $actualFile ) { + + $expected = $this->readFileContent($expectedFile); + + if (empty($expected)) { + return false; + } + + $generated = $this->readFileContent($actualFile); + + if (empty($generated)) { + return false; + } + + if (strcmp($expected, $generated) !== 0) { + return false; + } + + return true; + + } + + + } \ No newline at end of file diff --git a/tests/EnumObjectBuilderTest.php b/tests/EnumObjectBuilderTest.php index 8d570c5..12fbc65 100644 --- a/tests/EnumObjectBuilderTest.php +++ b/tests/EnumObjectBuilderTest.php @@ -20,7 +20,7 @@ class EnumObjectBuilderTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/enum_objects'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'enum_objects'; } /** @@ -34,9 +34,11 @@ public function testBuildEmptyEnum() $objectName .= 'EnumObject'; $enumBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -53,9 +55,11 @@ public function testAddValue() $enumBuilder->addEnumValue('fixed_value'); $enumBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -74,9 +78,11 @@ public function testAddMultipleValues() $enumBuilder->addEnumValue('oneMoreValue'); $enumBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } } \ No newline at end of file diff --git a/tests/InputObjectClassBuilderTest.php b/tests/InputObjectClassBuilderTest.php index a9dc712..0861df2 100644 --- a/tests/InputObjectClassBuilderTest.php +++ b/tests/InputObjectClassBuilderTest.php @@ -16,7 +16,7 @@ class InputObjectClassBuilderTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/input_objects'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'input_objects'; } /** @@ -35,9 +35,11 @@ public function testAddScalarValue() $classBuilder->addScalarValue('valOne'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -58,9 +60,11 @@ public function testAddMultipleScalarValues() $classBuilder->addScalarValue('val_two'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -80,9 +84,11 @@ public function testAddListValue() $classBuilder->addListValue('listOne', ''); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -103,9 +109,11 @@ public function testAddMultipleListValues() $classBuilder->addListValue('list_two', ''); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -125,9 +133,11 @@ public function testAddInputObjectValue() $classBuilder->addInputObjectValue('inputObject', 'WithListValue'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -148,9 +158,11 @@ public function testAddMultipleInputObjectValues() $classBuilder->addInputObjectValue('inputObjectTwo', '_TestFilter'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -169,9 +181,11 @@ public function testInputObjectIntegration() $classBuilder->addInputObjectValue('testFilter', '_TestFilter'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } } \ No newline at end of file diff --git a/tests/QueryObjectClassBuilderTest.php b/tests/QueryObjectClassBuilderTest.php index f9ecebf..12d9311 100644 --- a/tests/QueryObjectClassBuilderTest.php +++ b/tests/QueryObjectClassBuilderTest.php @@ -14,7 +14,7 @@ class QueryObjectClassBuilderTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/query_objects'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'query_objects'; } /** @@ -28,9 +28,11 @@ public function testBuildEmptyQueryObject() $objectName .= 'QueryObject'; $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -45,9 +47,11 @@ public function testBuildRootQueryObject() $objectName .= 'QueryObject'; $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -63,9 +67,11 @@ public function testAddSimpleSelector() $classBuilder->addScalarField('name'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -84,9 +90,11 @@ public function testAddMultipleSimpleSelectors() $classBuilder->addScalarField('last_name'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -102,9 +110,11 @@ public function testAddObjectSelector() $classBuilder->addObjectField('others', 'Other', 'RootOthers'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -123,9 +133,11 @@ public function testAddMultipleObjectSelectors() $classBuilder->addObjectField('left_objects', 'Left', 'MultipleObjectSelectorsLeftObjects'); $classBuilder->build(); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } } \ No newline at end of file diff --git a/tests/QueryObjectTest.php b/tests/QueryObjectTest.php index 8bdf31c..8f0e641 100644 --- a/tests/QueryObjectTest.php +++ b/tests/QueryObjectTest.php @@ -28,6 +28,11 @@ public function setUp(): void $this->queryObject = new SimpleQueryObject('simples'); } + private function replaceWhitespace(string $string) { + + return str_replace(["\t","\n","\r","\0","\x0B"],'', $string ); + } + /** * @covers \GraphQL\SchemaObject\QueryObject::__construct * @covers \GraphQL\SchemaObject\QueryObject::getQuery @@ -36,23 +41,25 @@ public function testConstruct() { $object = new SimpleQueryObject(); $object->selectScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( + 'query { Simple { scalar } -}', - (string) $object->getQuery()); +}'), + $this->replaceWhitespace($object->getQuery())); + $object = new SimpleQueryObject('test'); $object->selectScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( 'query { test { scalar } -}', - (string) $object->getQuery()); +}'), + $this->replaceWhitespace($object->getQuery())); } /** @@ -72,28 +79,28 @@ public function testEmptySelectionSet() public function testSelectFields() { $this->queryObject->selectScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( 'query { simples { scalar } -}', - (string) $this->queryObject->getQuery() +}'), + $this->replaceWhitespace($this->queryObject->getQuery()) ); $this->queryObject->selectAnotherScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( 'query { simples { scalar anotherScalar } -}', - (string) $this->queryObject->getQuery() +}'), + $this->replaceWhitespace($this->queryObject->getQuery()) ); $this->queryObject->selectSiblings()->selectScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( 'query { simples { scalar @@ -102,8 +109,8 @@ public function testSelectFields() scalar } } -}', - (string) $this->queryObject->getQuery() +}'), + $this->replaceWhitespace($this->queryObject->getQuery()) ); } @@ -114,15 +121,15 @@ public function testSelectFields() public function testSelectSubFieldsWithArguments() { $this->queryObject->selectSiblings((new SimpleSiblingsArgumentObject())->setFirst(5)->setIds([1,2]))->selectScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( 'query { simples { siblings(first: 5 ids: [1, 2]) { scalar } } -}', - (string) $this->queryObject->getQuery() +}'), + $this->replaceWhitespace($this->queryObject->getQuery()) ); $this->setUp(); @@ -141,15 +148,15 @@ public function setField($field) { ) ) ->selectScalar(); - $this->assertEquals( + $this->assertEquals( $this->replaceWhitespace( 'query { simples { siblings(obj: {field: "something"}) { scalar } } -}', - (string) $this->queryObject->getQuery() +}'), + $this->replaceWhitespace($this->queryObject->getQuery()) ); } } diff --git a/tests/SchemaClassGeneratorTest.php b/tests/SchemaClassGeneratorTest.php index 28122f9..77923e9 100644 --- a/tests/SchemaClassGeneratorTest.php +++ b/tests/SchemaClassGeneratorTest.php @@ -44,13 +44,13 @@ public function testSetWriteDirectory() $this->classGenerator = new SchemaClassGenerator( new Client('') ); - $this->assertStringEndsWith('/php-graphql-oqm/schema_object', $this->classGenerator->getWriteDir()); + $this->assertStringEndsWith( DIRECTORY_SEPARATOR . 'php-graphql-oqm' . DIRECTORY_SEPARATOR . 'schema_object', $this->classGenerator->getWriteDir()); $this->classGenerator = new SchemaClassGenerator( new Client(''), static::getGeneratedFilesDir() ); - $this->assertStringEndsWith('/tests/files_generated', $this->classGenerator->getWriteDir()); + $this->assertStringEndsWith(DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'files_generated', $this->classGenerator->getWriteDir()); } /** @@ -167,9 +167,12 @@ public function testGenerateEnumObject() $this->classGenerator->generateEnumObject($objectName); $objectName .= 'EnumObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/enum_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "enum_objects". DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -215,9 +218,12 @@ public function testGenerateInputObjectWithScalarValues() $this->classGenerator->generateInputObject($objectName); $objectName .= 'InputObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/input_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "input_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -278,9 +284,12 @@ public function testGenerateInputObjectWithListValues() $this->classGenerator->generateInputObject($objectName); $objectName .= 'InputObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/input_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "input_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -344,9 +353,12 @@ public function testGenerateInputObjectWithNestedObjectValues() $this->classGenerator->generateInputObject($objectName); $objectName .= 'InputObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/input_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "input_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -383,9 +395,12 @@ public function testGenerateArgumentsObjectWithScalarArgs() $this->classGenerator->generateArgumentsObject('WithMultipleScalarArgs', $argsArray); $objectName .= 'ArgumentsObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/arguments_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "arguments_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -452,9 +467,12 @@ public function testGenerateArgumentsObjectWithListArgs() $this->classGenerator->generateArgumentsObject($objectName, $argsArray); $objectName .= 'ArgumentsObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/arguments_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "arguments_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -511,9 +529,12 @@ public function testGenerateArgumentsObjectWithInputObjectArgs() $this->classGenerator->generateArgumentsObject($objectName, $argsArray); $objectName .= 'ArgumentsObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/arguments_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "arguments_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -560,9 +581,12 @@ public function testGenerateQueryObjectWithScalarFields() $this->classGenerator->generateQueryObject($objectName); $objectName .= 'QueryObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/query_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "query_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -637,9 +661,12 @@ public function testGenerateQueryObjectWithObjectFields() $objectName .= 'QueryObject'; $this->classGenerator->generateQueryObject($objectName); - $this->assertFileEquals( - static::getExpectedFilesDir() . "/query_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "query_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } @@ -663,9 +690,12 @@ public function testGenerateRootObject() $this->classGenerator->generateRootQueryObject(); $objectName = 'RootQueryObject'; - $this->assertFileEquals( - static::getExpectedFilesDir() . "/query_objects/$objectName.php", - static::getGeneratedFilesDir() . "/$objectName.php" + + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . "query_objects" . DIRECTORY_SEPARATOR . $objectName . ".php", + static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . $objectName . ".php" + ) ); } diff --git a/tests/TraitFileTest.php b/tests/TraitFileTest.php index a4fb83d..45490ed 100644 --- a/tests/TraitFileTest.php +++ b/tests/TraitFileTest.php @@ -12,7 +12,7 @@ class TraitFileTest extends CodeFileTestCase */ protected static function getExpectedFilesDir() { - return parent::getExpectedFilesDir() . '/traits'; + return parent::getExpectedFilesDir() . DIRECTORY_SEPARATOR . 'traits'; } /** @@ -28,7 +28,11 @@ public function testEmptyTrait() $trait = new TraitFile(static::getGeneratedFilesDir(), $fileName); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -46,7 +50,11 @@ public function testTraitWithNamespace() $trait->setNamespace("GraphQL\Test"); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -64,7 +72,11 @@ public function testTraitWithEmptyNamespace() $trait->setNamespace(''); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -83,7 +95,11 @@ public function testTraitWithImports() $trait->addImport("GraphQL\Client"); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -101,7 +117,11 @@ public function testTraitWithEmptyImport() $trait->addImport(""); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -123,7 +143,11 @@ public function testTraitWithNamespaceAndImports() $trait->addImport("GraphQL\\Client"); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -143,7 +167,11 @@ public function testTraitWithProperties() $trait->addProperty('property_three'); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); return $trait; } @@ -163,7 +191,11 @@ public function testTraitWithEmptyProperty() $trait->addProperty(''); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -176,11 +208,15 @@ public function testTraitWithEmptyProperty() */ public function testTraitWithDuplicateProperties(TraitFile $trait) { + $fileName = $trait->getFileName(); // Adding the same property again $trait->addProperty('property1'); - $fileName = $trait->getFileName(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -205,7 +241,11 @@ public function testTraitWithPropertiesAndValues() $trait->addProperty('propertySeven', 7.7); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -227,7 +267,11 @@ public function testTraitWithOneMethod() ); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -254,7 +298,11 @@ public function testTraitWithMultipleMethods() ); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -272,7 +320,11 @@ public function testTraitWithEmptyMethod() $trait->addMethod(''); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -300,7 +352,11 @@ public function testTraitWithPropertiesAndMethods() ); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php" , $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php" , $trait->getWritePath() + ) + ); } /** @@ -331,6 +387,11 @@ public function testTraitWithEverything() ); $trait->writeFile(); - $this->assertFileEquals(static::getExpectedFilesDir() . "/$fileName.php", $trait->getWritePath()); + $this->assertTrue( + $this->assertFileEqualsIgnoreWhitespace( + static::getExpectedFilesDir() . DIRECTORY_SEPARATOR . $fileName . ".php", $trait->getWritePath() + ) + ); + } } From f0d8c85ce77773d063077497b41a56b81e86bef8 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 4 Sep 2019 22:03:57 +0300 Subject: [PATCH 2/3] Skipped testUnwritableDirInConstructor(), testUnwritableDir() on Windows; --- tests/AbstractCodeFileTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AbstractCodeFileTest.php b/tests/AbstractCodeFileTest.php index 3d97dca..3f5fb16 100644 --- a/tests/AbstractCodeFileTest.php +++ b/tests/AbstractCodeFileTest.php @@ -61,7 +61,7 @@ public function testInvalidWriteDirInConstructor() /** * @testdox Test the behavior of the constructor when provided with a non-writable directory * - * @requires OS ^Windows + * @requires OSFAMILY BSD|Darwin|Solaris|Linux|unknown * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::__construct() * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::validateDirectory */ @@ -97,7 +97,7 @@ public function testInvalidWriteDir() /** * @testdox Test the behavior of changeWriteDir method when provided with a non-writable directory * - * @requires OS ^Windows + * @requires OSFAMILY BSD|Darwin|Solaris|Linux|unknown * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::changeWriteDir * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::validateDirectory */ From 00bba67306be97ffc80eb0e42ed4ee5eb4282d7b Mon Sep 17 00:00:00 2001 From: user Date: Wed, 4 Sep 2019 22:19:40 +0300 Subject: [PATCH 3/3] Skipped testUnwritableDirInConstructor(), testUnwritableDir() on Windows; --- tests/AbstractCodeFileTest.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/AbstractCodeFileTest.php b/tests/AbstractCodeFileTest.php index 3f5fb16..f0e02b4 100644 --- a/tests/AbstractCodeFileTest.php +++ b/tests/AbstractCodeFileTest.php @@ -61,13 +61,21 @@ public function testInvalidWriteDirInConstructor() /** * @testdox Test the behavior of the constructor when provided with a non-writable directory * - * @requires OSFAMILY BSD|Darwin|Solaris|Linux|unknown * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::__construct() * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::validateDirectory */ public function testUnwritableDirInConstructor() { + $uname = strtolower(php_uname()); + + if (strpos($uname, "darwin") !== false) { + // It's OSX + } + elseif (strpos($uname, "win") !== false) { + $this->markTestSkipped('Skipped on WIN'); + } + $testDir = static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR . 'unwritable-constructor'; mkdir($testDir); chmod($testDir, 0444); @@ -97,12 +105,20 @@ public function testInvalidWriteDir() /** * @testdox Test the behavior of changeWriteDir method when provided with a non-writable directory * - * @requires OSFAMILY BSD|Darwin|Solaris|Linux|unknown * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::changeWriteDir * @covers \GraphQL\SchemaGenerator\CodeGenerator\CodeFile\AbstractCodeFile::validateDirectory */ public function testUnwritableDir() { + $uname = strtolower(php_uname()); + + if (strpos($uname, "darwin") !== false) { + // It's OSX + } + elseif (strpos($uname, "win") !== false) { + $this->markTestSkipped('Skipped on WIN'); + } + $testDir = static::getGeneratedFilesDir() . DIRECTORY_SEPARATOR .'unwritable'; mkdir($testDir); chmod($testDir, 0444);