diff --git a/src/Lib/Configuration.php b/src/Lib/Configuration.php index b8d6a516..a9f1166b 100644 --- a/src/Lib/Configuration.php +++ b/src/Lib/Configuration.php @@ -190,14 +190,12 @@ public function setYml(string $yml) } $path = $this->root . $yml; - if ((!file_exists($path) && !is_writable($path)) || !touch($path)) { + if (!file_exists($path)) { throw new InvalidArgumentException( sprintf( - "Invalid yml: `%s`. yml must exist on the file system. An attempt was made to create %s, but - permission was denied or the file path is bad. Either fix the file system permissions, create the - file and/or both. $message", - $yml, - $path + 'A YML file is required but none was found at "%s". See "%s" for a sample file.', + $path, + '$vendor/cnizzardini/cakephp-swagger-bake/assets/swagger.yml' ) ); } diff --git a/tests/TestCase/Lib/ConfigurationTest.php b/tests/TestCase/Lib/ConfigurationTest.php index ed33f7df..f6356e3e 100644 --- a/tests/TestCase/Lib/ConfigurationTest.php +++ b/tests/TestCase/Lib/ConfigurationTest.php @@ -1,10 +1,11 @@ expectException(\LogicException::class); - $this->expectExceptionMessageMatches("/Property nope does not exist/"); + $this->expectException(LogicException::class); + $this->expectExceptionMessageMatches('/Property nope does not exist/'); $configs = array_merge(self::DEFAULT_CONFIGS, ['nope' => 'nope']); new Configuration($configs, SWAGGER_BAKE_TEST_APP); } @@ -51,13 +52,6 @@ public function test_constructor_throws_exception_when_config_arg_missing_requir /** * @dataProvider dataProviderInvalidConfig - * - * @param string $property The config property - * @param mixed $value The value of the $property - * @param string $exceptionClass The expected exception - * @param string $exceptionMsg A string the exception message should contain - * - * @return void */ public function test_invalid_configs_should_throw_exceptions_with_invalid_data( string $property, @@ -66,7 +60,7 @@ public function test_invalid_configs_should_throw_exceptions_with_invalid_data( string $exceptionMsg ): void { if (!class_exists($exceptionClass)) { - throw new \InvalidArgumentException("$exceptionClass is not a class. Test cannot be run."); + throw new InvalidArgumentException("$exceptionClass is not a class. Test cannot be run."); } $this->expectException($exceptionClass); $this->expectExceptionMessageMatches("/$exceptionMsg/"); @@ -85,15 +79,15 @@ public static function dataProviderInvalidConfig(): array $invalidPath = '/' . '..' . DS . '..' . DS . '..' . DS . '..' . DS . '..' . DS . '..' . DS . '..' . DS . '..' . DS; return [ - ['prefix', 'nope', \InvalidArgumentException::class, 'Invalid prefix'], - ['yml', 'nope', \InvalidArgumentException::class, 'Value should start with'], - ['yml', $invalidPath . 'nope', \InvalidArgumentException::class, 'yml must exist on the file'], - ['json', 'nope', \InvalidArgumentException::class, 'Value should start with'], - ['json', $invalidPath . 'nope', \InvalidArgumentException::class, 'Config value for `json` must exist'], - ['webPath', 'nope', \InvalidArgumentException::class, 'Invalid webPath'], - ['docType', 'nope', \InvalidArgumentException::class, 'Invalid docType'], - ['editActionMethods', ['nope'], \InvalidArgumentException::class, 'Invalid editActionMethod'], - ['connectionName', 'nope', \InvalidArgumentException::class, 'Invalid connectionName'], + ['prefix', 'nope', InvalidArgumentException::class, 'Invalid prefix'], + ['yml', 'nope', InvalidArgumentException::class, 'Value should start with'], + ['yml', $invalidPath . 'nope', InvalidArgumentException::class, 'A YML file is required but none was found'], + ['json', 'nope', InvalidArgumentException::class, 'Value should start with'], + ['json', $invalidPath . 'nope', InvalidArgumentException::class, 'Config value for `json` must exist'], + ['webPath', 'nope', InvalidArgumentException::class, 'Invalid webPath'], + ['docType', 'nope', InvalidArgumentException::class, 'Invalid docType'], + ['editActionMethods', ['nope'], InvalidArgumentException::class, 'Invalid editActionMethod'], + ['connectionName', 'nope', InvalidArgumentException::class, 'Invalid connectionName'], ]; } -} \ No newline at end of file +} diff --git a/tests/TestCase/Lib/Operation/OperationResponseAssociationTest.php b/tests/TestCase/Lib/Operation/OperationResponseAssociationTest.php index eb6e2583..7470d338 100644 --- a/tests/TestCase/Lib/Operation/OperationResponseAssociationTest.php +++ b/tests/TestCase/Lib/Operation/OperationResponseAssociationTest.php @@ -1,4 +1,5 @@ ['\SwaggerBakeTest\App\\'], 'entities' => ['\SwaggerBakeTest\App\\'], 'tables' => ['\SwaggerBakeTest\App\\'], - ] + ], ], SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner(new Router(), $this->config); @@ -182,7 +181,7 @@ public function test_associate_one(): void associations: ['table' => 'EmployeeSalaries', 'whiteList' => ['Employees']] )); - /** @var SchemaProperty $schemaProperty */ + /** @var \SwaggerBake\Lib\OpenApi\SchemaProperty $schemaProperty */ $schemaProperty = $schema->getProperties()['employee']; $this->assertEquals('employee', $schemaProperty->getName()); } @@ -200,4 +199,4 @@ public function test_associate_throws_exception_when_association_not_found(): vo )); $this->expectExceptionMessageMatches('/OpenApiResponse association not found/'); } -} \ No newline at end of file +}