diff --git a/tests/Unit/Exception/ComponentExceptionTest.php b/tests/Unit/Exception/ComponentExceptionTest.php index d832a2573..a569fabd5 100644 --- a/tests/Unit/Exception/ComponentExceptionTest.php +++ b/tests/Unit/Exception/ComponentExceptionTest.php @@ -9,32 +9,37 @@ function ($argument) { $exceptionObject = ComponentException::throwNotStringOrArray($argument); $type = \gettype($argument); - - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of ComponentException class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame("{$argument} variable is not a string or array but rather {$type}", $exceptionObject->getMessage(), "Strings for message if item is {$type} do not match!"); - - }) - ->with('exceptionArguments'); - - test('Checks if the throwNotStringOrArray method functions correctly with objects.', - function () { - - $object = new stdClass(); - $exceptionObject = ComponentException::throwNotStringOrArray($object); - - $this->assertIsObject($exceptionObject, "The object should be an instance of ComponentException class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame('Object couldn\'t be converted to string. Please provide only string or array.', $exceptionObject->getMessage(), "Strings for 'Object couldn't be converted to string' message do not match!"); - - }); + $message = "{$argument} variable is not a string or array but rather {$type}"; + + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(ComponentException::class) + ->toHaveProperty('message') + ->and($message) + ->toEqual($exceptionObject->getMessage()); +}) +->with('exceptionArguments'); + +test('Checks if the throwNotStringOrArray method functions correctly with objects.', +function () { + + $object = new stdClass(); + $exceptionObject = ComponentException::throwNotStringOrArray($object); + + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(ComponentException::class) + ->toHaveProperty('message') + ->and('Object couldn\'t be converted to string. Please provide only string or array.') + ->toEqual($exceptionObject->getMessage()); +}); test('Checks if throwUnableToLocateComponent method will return correct response.', function () { $component = 'nonexistent'; $output = ComponentException::throwUnableToLocateComponent($component); - $this->assertIsObject($output, "The {$output} should be an instance of ComponentException class"); - $this->assertObjectHasProperty('message', $output, "Object doesn't contain message attribute"); - $this->assertSame("Unable to locate component by path: {$component}", $output->getMessage(), "Strings for 'Unable to locate component by path' message do not match!"); + expect($output)->toBeObject() + ->toBeInstanceOf(ComponentException::class) + ->toHaveProperty('message') + ->and("Unable to locate component by path: {$component}") + ->toEqual($output->getMessage()); }); diff --git a/tests/Unit/Exception/FailedToLoadViewTest.php b/tests/Unit/Exception/FailedToLoadViewTest.php index 155c43bfc..a5829c451 100644 --- a/tests/Unit/Exception/FailedToLoadViewTest.php +++ b/tests/Unit/Exception/FailedToLoadViewTest.php @@ -11,8 +11,11 @@ $exception = new Exception('Error message'); $exceptionObject = FailedToLoadView::viewException($uri, $exception); + $message = "Could not load the View URI: {$uri}. Reason: {$exception->getMessage()}."; - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of FailedToLoadView class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame("Could not load the View URI: {$uri}. Reason: {$exception->getMessage()}.", $exceptionObject->getMessage(), "Strings for exception messages do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(FailedToLoadView::class) + ->toHaveProperty('message') + ->and($message) + ->toEqual($exceptionObject->getMessage()); }); diff --git a/tests/Unit/Exception/InvalidBlockTest.php b/tests/Unit/Exception/InvalidBlockTest.php index 2d19816b8..dc3fdee60 100644 --- a/tests/Unit/Exception/InvalidBlockTest.php +++ b/tests/Unit/Exception/InvalidBlockTest.php @@ -8,18 +8,22 @@ $missingBlocks = InvalidBlock::missingBlocksException(); - $this->assertIsObject($missingBlocks, "The {$missingBlocks} should be an instance of InvalidBlock class"); - $this->assertObjectHasProperty('message', $missingBlocks, "Object doesn't contain message attribute"); - $this->assertSame('There are no blocks added in your project.', $missingBlocks->getMessage(), "Strings for message if there are no blocks added to the project do not match!"); + expect($missingBlocks)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and('There are no blocks added in your project.') + ->toEqual($missingBlocks->getMessage()); }); test('Checks if missingComponentsException will return correct response.', function () { $missingComponents = InvalidBlock::missingComponentsException(); - $this->assertIsObject($missingComponents); - $this->assertObjectHasProperty('message', $missingComponents); - $this->assertSame('There are no components added in your project.', $missingComponents->getMessage(), "Strings for message if there are no components added to the project do not match!"); + expect($missingComponents)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and('There are no components added in your project.') + ->toEqual($missingComponents->getMessage()); }); test('Checks if missingNameException will return correct response.', function () { @@ -27,9 +31,11 @@ $blockPath = 'some/random/path'; $missingName = InvalidBlock::missingNameException($blockPath); - $this->assertIsObject($missingName); - $this->assertObjectHasProperty('message', $missingName); - $this->assertSame("Block in this path {$blockPath} is missing blockName key in its manifest.json.", $missingName->getMessage(), "Strings for message if blockName key is missing in manifest.json do not match!"); + expect($missingName)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Block in this path {$blockPath} is missing blockName key in its manifest.json.") + ->toEqual($missingName->getMessage()); }); test('Checks if missingViewException will return correct response.', function () { @@ -38,9 +44,11 @@ $blockPath = 'some/random/path'; $missingView = InvalidBlock::missingViewException($blockName, $blockPath); - $this->assertIsObject($missingView); - $this->assertObjectHasProperty('message', $missingView); - $this->assertSame("Block with this name {$blockName} is missing view template. Template name should be called {$blockName}.php, and it should be located in this path {$blockPath}", $missingView->getMessage(), "Strings for message if block is missing view template do not match!"); + expect($missingView)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Block with this name {$blockName} is missing view template. Template name should be called {$blockName}.php, and it should be located in this path {$blockPath}") + ->toEqual($missingView->getMessage()); }); test('Checks if missingRenderViewException will return correct response.', function () { @@ -48,9 +56,11 @@ $blockPath = 'some/random/path'; $missingRenderView = InvalidBlock::missingRenderViewException($blockPath); - $this->assertIsObject($missingRenderView); - $this->assertObjectHasProperty('message', $missingRenderView); - $this->assertSame("Block view is missing in the provided path. Please check if {$blockPath} is the right path for your block view.", $missingRenderView->getMessage(), "Strings for message if block view is missing provided path do not match!"); + expect($missingRenderView)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Block view is missing in the provided path. Please check if {$blockPath} is the right path for your block view.") + ->toEqual($missingRenderView->getMessage()); }); test('Checks if missingSettingsManifestException will return correct response.', function () { @@ -58,9 +68,11 @@ $manifestPath = 'some/random/path'; $missingManifestPath = InvalidBlock::missingSettingsManifestException($manifestPath); - $this->assertIsObject($missingManifestPath); - $this->assertObjectHasProperty('message', $missingManifestPath); - $this->assertSame("Global blocks settings manifest.json is missing on this location: {$manifestPath}.", $missingManifestPath->getMessage(), "Strings for message if global blocks settings manifest.json is missing do not match!"); + expect($missingManifestPath)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Global blocks settings manifest.json is missing on this location: {$manifestPath}.") + ->toEqual($missingManifestPath->getMessage()); }); test('Checks if missingWrapperManifestException will return correct response.', function () { @@ -68,9 +80,11 @@ $manifestPath = 'some/random/path'; $missingManifestPath = InvalidBlock::missingWrapperManifestException($manifestPath); - $this->assertIsObject($missingManifestPath); - $this->assertObjectHasProperty('message', $missingManifestPath); - $this->assertSame("Wrapper blocks settings manifest.json is missing on this location: {$manifestPath}.", $missingManifestPath->getMessage(), "Strings for message if wrapper blocks settings manifest.json is missing do not match!"); + expect($missingManifestPath)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Wrapper blocks settings manifest.json is missing on this location: {$manifestPath}.") + ->toEqual($missingManifestPath->getMessage()); }); test('Checks if missingComponentManifestException will return correct response.', function () { @@ -78,9 +92,11 @@ $manifestPath = 'some/random/path'; $missingComponentManifest = InvalidBlock::missingComponentManifestException($manifestPath); - $this->assertIsObject($missingComponentManifest); - $this->assertObjectHasProperty('message', $missingComponentManifest); - $this->assertSame("Component manifest.json is missing on this location: {$manifestPath}.", $missingComponentManifest->getMessage(), "Strings for message if component manifest.json is missing do not match!"); + expect($missingComponentManifest)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Component manifest.json is missing on this location: {$manifestPath}.") + ->toEqual($missingComponentManifest->getMessage()); }); test('Checks if missingWrapperViewException will return correct response.', function () { @@ -88,16 +104,20 @@ $wrapperPath = 'some/random/path'; $missingWrapperView = InvalidBlock::missingWrapperViewException($wrapperPath); - $this->assertIsObject($missingWrapperView); - $this->assertObjectHasProperty('message', $missingWrapperView); - $this->assertSame("Wrapper view is missing. Template should be located in this path {$wrapperPath}", $missingWrapperView->getMessage(), "Strings for message if wrapper view is missing do not match!"); + expect($missingWrapperView)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and("Wrapper view is missing. Template should be located in this path {$wrapperPath}") + ->toEqual($missingWrapperView->getMessage()); }); test('Checks if missingNamespaceException will return correct response.', function () { $missingNamespace = InvalidBlock::missingNamespaceException(); - $this->assertIsObject($missingNamespace); - $this->assertObjectHasProperty('message', $missingNamespace); - $this->assertSame('Global Blocks settings manifest.json is missing a key called namespace. This key prefixes all block names.', $missingNamespace->getMessage(), "Strings for message global settings manifest.json is missing a key called namespace do not match!"); + expect($missingNamespace)->toBeObject() + ->toBeInstanceOf(InvalidBlock::class) + ->toHaveProperty('message') + ->and('Global Blocks settings manifest.json is missing a key called namespace. This key prefixes all block names.') + ->toEqual($missingNamespace->getMessage()); }); diff --git a/tests/Unit/Exception/InvalidCallbackTest.php b/tests/Unit/Exception/InvalidCallbackTest.php index 3b83ca497..d423c15e4 100644 --- a/tests/Unit/Exception/InvalidCallbackTest.php +++ b/tests/Unit/Exception/InvalidCallbackTest.php @@ -10,7 +10,9 @@ $exceptionObject = InvalidCallback::fromCallback($callback); - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of InvalidBlock class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame("The callback {$callback} is not recognized and cannot be registered.", $exceptionObject->getMessage(), "Strings for message if callback isn't recognised do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(InvalidCallback::class) + ->toHaveProperty('message') + ->and("The callback {$callback} is not recognized and cannot be registered.") + ->toEqual($exceptionObject->getMessage()); }); diff --git a/tests/Unit/Exception/InvalidManifestTest.php b/tests/Unit/Exception/InvalidManifestTest.php index 20621a842..cb305b4cc 100644 --- a/tests/Unit/Exception/InvalidManifestTest.php +++ b/tests/Unit/Exception/InvalidManifestTest.php @@ -10,9 +10,11 @@ $exceptionObject = InvalidManifest::missingManifestItemException($key); - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of InvalidManifest class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame("{$key} key does not exist in manifest.json. Please check if provided key is correct.", $exceptionObject->getMessage(), "Strings for message if manifest key is missing do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(InvalidManifest::class) + ->toHaveProperty('message') + ->and("{$key} key does not exist in manifest.json. Please check if provided key is correct.") + ->toEqual($exceptionObject->getMessage()); }); test('Checks if the missingManifestException method will return correct response.', function () { @@ -21,9 +23,11 @@ $exceptionObject = InvalidManifest::missingManifestException($manifestPath); - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of InvalidManifest class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame("manifest.json is missing at this path: {$manifestPath}. Bundle the theme before using it. Or your bundling process is returning an error.", $exceptionObject->getMessage(), "Strings for message if manifest is missing do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(InvalidManifest::class) + ->toHaveProperty('message') + ->and("manifest.json is missing at this path: {$manifestPath}. Bundle the theme before using it. Or your bundling process is returning an error.") + ->toEqual($exceptionObject->getMessage()); }); test('Checks if the manifestStructureException method will return correct response.', function () { @@ -32,7 +36,9 @@ $exceptionObject = InvalidManifest::manifestStructureException($errorMessage); - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of InvalidManifest class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame($errorMessage, $exceptionObject->getMessage(), "Strings for manifest structure error message do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(InvalidManifest::class) + ->toHaveProperty('message') + ->and($errorMessage) + ->toEqual($exceptionObject->getMessage()); }); diff --git a/tests/Unit/Exception/InvalidServiceTest.php b/tests/Unit/Exception/InvalidServiceTest.php index e76337af0..7edac3e84 100644 --- a/tests/Unit/Exception/InvalidServiceTest.php +++ b/tests/Unit/Exception/InvalidServiceTest.php @@ -10,7 +10,9 @@ $exceptionObject = InvalidService::fromService($service); - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of InvalidService class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame("The service {$service} is not recognized and cannot be registered.", $exceptionObject->getMessage(), "Strings for message if service name isn't recognised do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(InvalidService::class) + ->toHaveProperty('message') + ->and("The service {$service} is not recognized and cannot be registered.") + ->toEqual($exceptionObject->getMessage()); }); diff --git a/tests/Unit/Exception/PluginActivationFailureTest.php b/tests/Unit/Exception/PluginActivationFailureTest.php index 6220d78ad..19fff6aa6 100644 --- a/tests/Unit/Exception/PluginActivationFailureTest.php +++ b/tests/Unit/Exception/PluginActivationFailureTest.php @@ -10,7 +10,9 @@ $exceptionObject = PluginActivationFailure::activationMessage($message); - $this->assertIsObject($exceptionObject, "The {$exceptionObject} should be an instance of PluginActivationFailure class"); - $this->assertObjectHasProperty('message', $exceptionObject, "Object doesn't contain message attribute"); - $this->assertSame($message, $exceptionObject->getMessage(), "Strings for error activation message do not match!"); + expect($exceptionObject)->toBeObject() + ->toBeInstanceOf(PluginActivationFailure::class) + ->toHaveProperty('message') + ->and($message) + ->toEqual($exceptionObject->getMessage()); });