1. Go to this page and download the library: Download ez-php/testing-application library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ez-php / testing-application example snippets
use EzPhp\Testing\ApplicationTestCase;
final class MyTest extends ApplicationTestCase
{
protected function configureApplication(Application $app): void
{
$app->register(MyServiceProvider::class);
}
public function testSomething(): void
{
$service = $this->app()->make(MyService::class);
// ...
}
}
use EzPhp\Testing\DatabaseTestCase;
final class UserRepositoryTest extends DatabaseTestCase
{
protected function getBasePath(): string
{
// Return path to an app root with config/db.php
}
public function testInsert(): void
{
$this->pdo()->exec("INSERT INTO users (name) VALUES ('Alice')");
// rolled back automatically after the test
}
}
use EzPhp\Testing\HttpTestCase;
final class ApiTest extends HttpTestCase
{
protected function configureApplication(Application $app): void
{
$app->register(ApiRouteProvider::class);
}
public function testGetUser(): void
{
$this->get('/users/1')->assertOk()->assertJson(['id' => 1]);
}
}