-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cover generators with tests #65
base: master
Are you sure you want to change the base?
Conversation
@KonstantinLapkovsky please check all other mock traits according my comments |
# Conflicts: # phpunit.xml # tests/Support/NovaTestMockTrait.php
return $this->mockNativeFunction('\\RonasIT\\Support\\Generators', 'class_exists', $result); | ||
} | ||
|
||
public function mockCheckingNonExistentNovaPackageExistence(): Mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function mockCheckingNonExistentNovaPackageExistence(): Mock | |
public function mockCheckingNovaPackageExistence(bool $result = false): Mock |
@@ -0,0 +1,75 @@ | |||
<?php | |||
|
|||
namespace RonasIT\Support\Tests\Support\Controller; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace RonasIT\Support\Tests\Support\Controller; | |
namespace RonasIT\Support\Tests\Support\ControllerGeneratorTest; |
@@ -0,0 +1,66 @@ | |||
<?php | |||
|
|||
namespace RonasIT\Support\Tests\Support\Shared; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace RonasIT\Support\Tests\Support\Shared; | |
namespace RonasIT\Support\Tests\Support; |
@@ -0,0 +1,74 @@ | |||
<?php | |||
|
|||
namespace RonasIT\Support\Tests\Support\NovaResource; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace RonasIT\Support\Tests\Support\NovaResource; | |
namespace RonasIT\Support\Tests\Support\NovaResourceGeneratorTest; |
@@ -0,0 +1,126 @@ | |||
<?php | |||
|
|||
namespace RonasIT\Support\Tests\Support\NovaTest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace RonasIT\Support\Tests\Support\NovaTest; | |
namespace RonasIT\Support\Tests\Support\NovaTestGeneratorTest; |
return $this->mockClassExistsFunction(false); | ||
} | ||
|
||
public function classExistsMethodCall(?string $path, ?string $className, bool $result = true): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like optional args are using only in the mockResourceGeneratorForNonExistingNovaResource
method. Could we use filled args there and remove optional here?
tests/ControllerGeneratorTest.php
Outdated
$this->removeRecursivelyGeneratedFolders(getcwd() . '/tests/vfs:'); | ||
} | ||
|
||
protected function removeRecursivelyGeneratedFolders(string $path): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move it to the parent class, but before please try to mock mk_dir_recursive
function, as we discussed, it may be helpfull and able you to remove this logic at all
tests/ControllerGeneratorTest.php
Outdated
$this->removeRecursivelyGeneratedFolders(getcwd() . '/vfs:'); | ||
$this->removeRecursivelyGeneratedFolders(getcwd() . '/tests/vfs:'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we implement clearVFS
and remove all available paths inside?
tests/NovaResourceGeneratorTest.php
Outdated
$this->assertEquals($this->getDatabaseAssertionData(), $fields); | ||
} | ||
|
||
public function getFieldsMock(): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move it to the fixture
tests/NovaResourceGeneratorTest.php
Outdated
]; | ||
} | ||
|
||
public function getDatabaseAssertionData(): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use such array inside the test cases without additional method
public function mockControllerGeneratorForExistingController(): void | ||
{ | ||
$this->mockClass(ControllerGenerator::class, [ | ||
$this->classExistsMethodCall('controllers', 'PostController') | ||
]); | ||
} | ||
|
||
public function mockControllerGeneratorForNotExistingService(): void | ||
{ | ||
$this->mockClass(ControllerGenerator::class, [ | ||
$this->classExistsMethodCall('controllers', 'PostController', false), | ||
$this->classExistsMethodCall('services', 'PostService', false) | ||
]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed, let's remove this methods and call such logic inside the tests
]); | ||
} | ||
|
||
public function mockConfigurations(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems we no need in this, let's try to define getPackageProviders
method inside the base test case
|
||
trait GeneratorMockTrait | ||
{ | ||
public function mockNativeFunction(string $namespace, string $name, $result): Mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check that such logic already exists in the laravel helpers package and use it
Issue #49