PHP code example of tipowerup / testbench

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

    

tipowerup / testbench example snippets




declare(strict_types=1);

namespace Tipowerup\MyExtension\Tests;

use Tipowerup\Testbench\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    protected function getExtensionBasePath(): string
    {
        return dirname(__DIR__);
    }

    protected function getExtensionProviders(): array
    {
        return [\Tipowerup\MyExtension\Extension::class];
    }
}



declare(strict_types=1);

uses(Tipowerup\MyExtension\Tests\TestCase::class)->in('Feature');
uses()->in('Unit');

abstract class TestCase extends BaseTestCase
{
    protected bool $runCoreMigrations = false;

    // ...
}

protected function setUp(): void
{
    parent::setUp();

    $this->runTiAdminMigrations();
}

protected function setUp(): void
{
    parent::setUp();

    $this->runExtensionMigrations(__DIR__.'/../database/migrations');
}

use Tipowerup\Testbench\Concerns\TestsMigrations;

// Assert migrate up creates tables, rollback removes them
$this->assertMigrationCycle($path, ['my_table', 'my_other_table']);

// Assert N up/down cycles succeed without errors
$this->assertSurvivesInstallCycles($path, ['my_table'], cycles: 3);

// Assert migrations don't touch core TI tables
$this->assertNoCoreTables($path);

// Assert all migrations have non-empty down() methods
$this->assertProperDownMethods($path);

// Assert schema accepts seed data after rollback+migrate
$this->assertSchemaAcceptsSeedData($path, 'my_table', ['name' => 'test'], ['name']);

use Tipowerup\Testbench\Concerns\TestsTIIntegration;

$this->assertParamsWork('my_key', 'my_value');
$this->assertExtensionRegistered('tipowerup.myextension');
$this->assertTIInstallCycle('tipowerup.myextension');
$this->assertCleanPurge('tipowerup.myextension', ['my_table']);
$this->assertNavigationRegistered(Extension::class, 'tools', 'my-item');
$this->assertPermissionsRegistered(Extension::class, ['Tipowerup.MyExtension.Manage']);

use Tipowerup\Testbench\Concerns\MocksTIServices;

// Mock with defaults
$mock = $this->mockExtensionManager();

// Override specific stubs
$mock = $this->mockExtensionManager(['hasExtension' => false]);

// Available mocks
$this->mockExtensionManager($overrides);
$this->mockHubManager($overrides);
$this->mockUpdateManager($overrides);
$this->mockPackageManifest($overrides);
$this->mockService(MyService::class, ['method' => 'return_value']);
xml
<phpunit bootstrap="vendor/tipowerup/testbench/src/bootstrap.php"
         colors="true"
         cacheDirectory=".phpunit.cache">
    <testsuites>
        <testsuite name="Tests">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
    <source>
        <