0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FuelPHP1.9 にPHPUnitをインストール

Posted at

FuelPHP1.9 にPHPUnitをインストール

  1. composerでphpunit/phpunitをインストール(12以上)
    1. composer.jsonに追記
    composer.json
    "phpunit/phpunit": "*"
    
    :pencil: PHP8.4なら13になります
    2. 追加
    php composer.phar update --dry-run
    
  2. packages\oil\config\oil.phpapp/config/oil.phpへコピー
  3. core\phpunit.xmlapp/phpunit.xmlへコピ―
  4. app/config/oil.phpを修正
oil.php
return [
    'phpunit' => [
        // vendor配下のオートローダー
        'autoload_path' => VENDORPATH . 'autoload.php',
        // vendor配下のphpunit
        'binary_path'   => VENDORPATH . 'bin/phpunit',
    ],
];

:pencil: VENDORPATHはFuelPHPで定義されています
5. app/phpunit.xmlを変更

phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" stopOnFailure="false" bootstrap="../core/bootstrap_phpunit.php">
	<php>
		<server name="doc_root" value="../../"/>
		<server name="app_path" value="xxx"/>
		<server name="core_path" value="xxx"/>
		<server name="package_path" value="xxx"/>
		<server name="vendor_path" value="xxx"/>
		<server name="FUEL_ENV" value="xxx"/>
	</php>
	<testsuites>
		<testsuite name="app">
			<directory suffix=".php">../app/tests</directory>
		</testsuite>
	</testsuites>
</phpunit>

:pencil: coreなどの不要な設定を削除
6. app/tests/配下にテストコードを記載

testdebug.php
<?php

declare(strict_types=1);

namespace Tests\Model;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use TestCase;

/**
 * tests.
 */
#[Group('model')]
class TestDebug extends TestCase
{
    /**
     * デフォルトテスト.
     */
    #[Test]
    public function testFoo(): void
    {
        $this->assertEquals(0, 0);
    }
}

:pencil: Groupを使用すると --group で指定が出来るようになります
:pencil: メソッド名のprefixtestにしてください
7. 実行

# 全て
php oil test
# modelグループのみ
php oil test --group=model

oilで phpunitの実行コマンド文字列を生成しているだけになりますので、直接phpunitを実行していただいて問題はありません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?