spiral / app

Spiral Framework Skeleton HTTP Application: Queue, Console, Cycle ORM
https://spiral.dev/
MIT License
191 stars 20 forks source link

feat(tests): add PHPUnit and test helper to the application #4

Closed krwu closed 4 years ago

krwu commented 4 years ago

To users who use this skeleton application, they should be able to start writing tests immediately.

I add PHPUnit and the startup configuration for the spiral app.

Usage:

  1. Every test class should extend Tests\TestCase, not PHPUnit\Framework\TestCase
  2. There are some helpful methods to interact with Console and Web Server ( codes was copied from tests of Spiral Framework. like $this->get(), $this->post, $this->request, $this->runCommand, etc.
krwu commented 4 years ago

Hoping that the framework could support more ability for writing tests as Laravel does.

wolfy-j commented 4 years ago

This is very good! I have no objections, most likely will add more test stubs or move some to an external package while writing the "Testing application" documentation. But this is a very good start. Thank you so much.

krwu commented 4 years ago

This is very good! I have no objections, most likely will add more test stubs or move some to an external package while writing the "Testing application" documentation. But this is a very good start. Thank you so much.

I think the framework should provide the testing component out of the box, including classes, traits, asserts and scaffold commands.

For example, like this:

php app.php create:test --unit UserEntityTest
<?php

declare(strict_types=1);

namespace Tests\Unit;

use Spiral\Testing\BaseTestCase;
use App\Entities\UserEntity as User;

class UserEntityTest extends BaseTestCase
{
    public function TestUserHasName()
    {
        $name = 'Foo';
        $user = new User($name);
        $this->assertEqual($name,  $user->getName());
    }
}
wolfy-j commented 4 years ago

Yes, I agree. However, currently the priority on completing the documentation. We have a massive backlog. :)

krwu commented 4 years ago

Yes, I agree. However, currently the priority on completing the documentation. We have a massive backlog. :)

I can understand it, hoping more and more developers will join and contribute to Spiral.