Open antoscarface opened 5 years ago
This is something we can dig deeper for the 2.1
release then. There is a basic configuration for PhpUnit on the application by default it would be great to extends the tools on the tests.
Awesome! Thank you! If I will discover something useful for this task, I will be happy to share it with you.
Today I've tried to use the Testing Laravel package.
After several improvements, it started work as it should.
The steps I did to make it work
Tests
namespace to Composer.
// composer.json
"require-dev": { "fzaninotto/faker": "^1.8", "mockery/mockery": "^1.2", "phpunit/phpunit": "^7.0", "symfony/var-dumper": "^4.2" }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } },
2. Added a `wp-load.php` to `tests\bootsrap.php`, in order make route system work correctly.
// tests\bootstrap.php
require DIR .'/../'. THEMOSIS_PUBLIC_DIR. '/cms/wp-load.php';
3. Added a `$_SERVER` variable to `phpunit.xml.dist`, in order to make to work `request` in tests, oherwise the `wp_dependencies_unique_hosts()` function will fail.
// phpunit.xml.dist
4. Utilized the Testing Package from Laravel.
5. Added console commands to scaffold tests.
It would be better if you don't load WordPress in the unit tests. To achieve better this, it might be useful to use a library such this: https://brain-wp.github.io/BrainMonkey/.
It loads and mocks all WordPress functionality, without loading it.
It would be better if you don't load WordPress in the unit tests.
I do agree, but for the feature tests you need not mocked WP functions, but real ones, e.g. if you do something like that
//...
/**
* A Test for view concert listing.
*
* @test
*/
public function userCanViewAConcertListing()
{
$concert = Concert::create([
'title' => 'The Red Cord',
//...
]);
$response = $this->get("/concerts/{$concert->id}");
$response->assertSeeText($concert->title);
// ...
}
@rumur Have you found any solution to integrate Model Factories in Tests?
Hi,
I'm successfully using al the components you integrated into Themosis and I see they mainly come from Laravel framework, that is great!
But, I've also seen that you haven't still integrated the testing suite of Laravel, that would be a great support to test the implementation of the Laravel components, such as routes, eloquent models, so on.. That is: https://laravel.com/docs/5.7/testing
In another note, I see that the testing suite is not in an incapsulated packagist library as for the other components, but it is here https://github.com/laravel/framework/tree/5.7/src/Illuminate/Foundation/Testing.
The only solution I see is to copy those classes and adding them under the
Themosis\Core\Testing
namespace and maybe they need to be adapted. So, before starting making some integration attempt, is it worth include those classes (all or a part) inside the framework of Themosis? Have you already tried? Have you some feedback.Thanks.