PHP code example of pierstoval / smoke-testing

1. Go to this page and download the library: Download pierstoval/smoke-testing 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/ */

    

pierstoval / smoke-testing example snippets




namespace App\Tests;

use Pierstoval\SmokeTesting\SmokeTestStaticRoutes;

class AllRoutesTest extends SmokeTestStaticRoutes
{
    // That's all!
}



namespace App\Tests;

use Pierstoval\SmokeTesting\FunctionalSmokeTester;
use Pierstoval\SmokeTesting\FunctionalTestData;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AllRoutesTest extends WebTestCase
{
    use FunctionalSmokeTester; // Allows using the "$this->runFunctionalTest()" method.
    
    public function testGet200(): void
    {
        $this->runFunctionalTest(
            FunctionalTestData::withUrl('/my-route')
                ->expectRouteName('my_successful_route')
                ->expectStatusCode(200)
                ->expectTextToBePresent('Hello world!')
        );
    }
}



namespace App\Tests;

use Pierstoval\SmokeTesting\FunctionalSmokeTester;
use Pierstoval\SmokeTesting\FunctionalTestData;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class AllRoutesTest extends WebTestCase
{
    use FunctionalSmokeTester;

    /**
     * @dataProvider provideTestUrls
     */
    public function testMyUrls(FunctionalTestData $testData): void
    {
        $this->runFunctionalTest($testData);
    }
    
    public function provideTestUrls(): \Generator
    {
        yield '/my-route' => FunctionalTestData::withUrl('/my-route')
                ->expectRouteName('my_successful_route')
                ->expectStatusCode(200)
                ->expectTextToBePresent('Hello world!');

        yield '/my-other-route' => FunctionalTestData::withUrl('/my-other-route')
                ->withHttpHeader('Authorization', 'Bearer 2d5b0cfb531745668')
                ->expectRouteName('my_other_route')
                ->expectStatusCode(200)
                ->expectTextToBePresent('{"message": "Bonjour!"}');
    }
}


// config/bundles.php
return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true, 'test' => true],
    // ...
    
    // Add this line ⬇
    Pierstoval\SmokeTesting\SmokeTestingBundle::class => ['dev' => true, 'test' => true],
];

  
  namespace App\Tests;
  use Pierstoval\SmokeTesting\FunctionalSmokeTester;
  use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  class FunctionalTest extends WebTestCase
  {
      use FunctionalSmokeTester;
    
      public function testRouteGet200WithMethodGet(): void
      {
          $this->runFunctionalTest(
              FunctionalTestData::withUrl('/200')
                  ->withMethod('GET')
                  ->expectRouteName('get_200')
                  ->appendCallableExpectation($this->assertStatusCodeLessThan500('GET', '/200'))
          );
      }
  
      // ...
  }
  

  
  namespace App\Tests;
  use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  class FunctionalTest extends WebTestCase
  {
      public function testRouteGet200WithMethodGet(): void
      {
          $client = static::createClient();
          $crawler = $client->request('GET', '/');
  
          static::assertLessThan(
              500,
              $client->getResponse()->getStatusCode(),
              'Request "GET /200" for route "get_200" returned an internal error.',
          );
      }
    
      // ...
  }