PHP code example of ablogcms / testing-framework

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

    

ablogcms / testing-framework example snippets



// tests/bootstrap.php(カスタムが必要なときだけ)

namespace Acms\Plugins\Foo\Tests\Unit;

use Acms\Plugins\Foo\Services\Foo\Helper;
use Acms\TestingFramework\TestCase;
use PHPUnit\Framework\Attributes\Test;

final class HelperTest extends TestCase
{
    #[Test]
    public function 先頭にアットマークを付与する(): void
    {
        $this->assertSame('@appleple', (new Helper())->formatHandle('appleple'));
    }
}

namespace Acms\Plugins\Foo\Tests\Integration;

use Acms\Plugins\Foo\Services\Foo\UserMapper;
use Acms\TestingFramework\DatabaseTestCase;
use Acms\TestingFramework\Seeder\UserSeeder;
use PHPUnit\Framework\Attributes\Test;

final class UserMapperTest extends DatabaseTestCase
{
    private int $blogId;

    protected function setUpDatabase(): void
    {
        $this->blogId = $this->createTestBlog(['blog_name' => 'テストブログ']);
    }

    #[Test]
    public function メールで有効ユーザーを特定する(): void
    {
        $userId = UserSeeder::seed($this->blogId, ['user_mail' => '[email protected]']);

        $result = (new UserMapper($this->blogId))->resolve('[email protected]');

        $this->assertSame($userId, $result['userId']);
    }
}

$blogId = BlogSeeder::seed(['blog_name' => 'テストブログ']);
$userId = UserSeeder::seed($blogId, ['user_mail' => '[email protected]', 'user_auth' => 'administrator']);
CategorySeeder::seed($blogId, [], 5); // 5 件まとめて作成します

use Acms\TestingFramework\Helpers\PluginActivator;

PluginActivator::activate('Foo', $blogId);
$this->assertTrue(PluginActivator::isActive('Foo', $blogId));


// tests/bootstrap.php
src/vendor/autoload.php'; // 同梱依存(onelogin/php-saml 等)
xml
<phpunit bootstrap="vendor/ablogcms/testing-framework/bootstrap.php">
neon
 vendor/ablogcms/testing-framework/phpstan/extension.neon
parameters:
  level: max
  # 本番は PHP 8.1〜8.5 対応。その範囲で解析する(新旧バージョン差の取りこぼしを防ぐ)
  phpVersion:
    min: 80100
    max: 80500
  paths:
    - src
    - tests          # テストも型チェックする(基盤の基底クラスは上の 
xml
<phpunit bootstrap="vendor/ablogcms/testing-framework/bootstrap.php" colors="true" cacheDirectory=".phpunit.cache">
  <testsuites>
    <testsuite name="plugins">
      <directory>plugins</directory>   <!-- 再帰で各プラグインの tests/ を拾う -->
    </testsuite>
  </testsuites>
  <php>
    <env name="ACMS_ROOT" value="/var/www/html"/>   <!-- コンテナ内の CMS ルート -->
  </php>
</phpunit>
neon
 vendor/ablogcms/testing-framework/phpstan/extension.neon
parameters:
  level: max
  paths:
    - plugins
  scanDirectories:
    - /var/www/html/php