Code Monkey home page Code Monkey logo

Comments (14)

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 確認したんですが、BcBakeが出力する bootstrap.php がテストが動くようになってませんでした。
修正しましたので、こちらを参考にしてみてください。
f8b6ee6

from bcbake.

binbin4649 avatar binbin4649 commented on July 20, 2024

@ryuring
ありがとうございます!
dev-5をfetchして、大量のワーニングが消え、ユニットテストが動き出しました。

ついでになんですが、
色々いじり回して、やっとこプラグインのテストが動くようになったんですが、
単純にプラグインをBakeしてテストを動かそうと思うと、fixtureを読み込まない、setUpでclassも読み込まずで、
ドキュメントルートからvendor/bin/phpunit、 でbasercms自体のテストを一通り動かすと、プラグインのテストも動くようになります。
ちなみにその全体テストは大量のエラーとワーニングが出て、いくつかのファイルも書き変わります。
とりあえずこれでプラグインのテストは動くようになったので良いんですが、こんなもんなんですかね?

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 あれ?

まず、プラグインのフォルダで次のコマンドを打つ事を前提としています。

../../vendor/bin/phpunit

fixture を読み込まないのは、これまでの fixture が非推奨になったからです。
FixtureFactoryを利用してください。
https://baserproject.github.io/5/core/unittest/fixture

テストは、BcTestCase を継承した方がやりやすいかもしれません。
こちらはコアのテスト作成のドキュメントですが参考にしてみてください。
https://baserproject.github.io/5/core/unittest/

from bcbake.

binbin4649 avatar binbin4649 commented on July 20, 2024

@ryuring
../../vendor/bin/phpunit
はい、プラグインのフォルダでテスト実行してます。

fixtureを読み込まないのもそうなんですが、

public function setUp(): void
    {
        parent::setUp();
        $this->Items = $this->getTableLocator()->get('Hoge.Items');
    }

setUpでclass(table)も読み込まないのです。
で、ドキュメントルートから、
vendor/bin/phpunit
を実行してbasercms全体のテストを1回実行すると、
fixtureもclassも読み込むようになります。
vendor/bin/phpunitを実行することで何かが変わってると思うのですが、それがなんなのか分からず、モヤモヤしてる感じです、、

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 実際にテスト的にプラグインを作成して、xdebug で setUp で止まるか試したところ止まりました。

スクリーンショット 2024-04-07 10 01 50

コマンドは次のような感じです

cd plugins/Catchup
../../vendor/bin/phpunit tests/TestCase/Model/Table/PostsTableTest.php

なお、テストを行う場合、事前に次の2つの準備が必要でした。

1.マイグレーションファイルを作成する
plugins/Catchup/config/Migrations 内に作成します。
参考) https://book.cakephp.org/migrations/3/ja/index.html

2.plugins/Catchup/tests/bootstrap.php で、プラグインが持つスキーマを構築する

// 一番最終行に記述
(new Migrator())->runMany([
    ['plugin' => 'Catchup']
]);

※ こちらは BcBake に入れておきます。

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 BcBake 側にマイグレーション処理を追加しておきました。
85358c7

from bcbake.

binbin4649 avatar binbin4649 commented on July 20, 2024

@ryuring
ありがとうございます。あとで試してみます。

from bcbake.

binbin4649 avatar binbin4649 commented on July 20, 2024

@ryuring
試した結果、やっぱり全体テストを1回実行しないとエラーになるようです。こちら原因が他にありそうなので、別途調べます。

たぶん別件なんですが、(そしてこのスレに書いて良いものなのか分からないのですが、)
plugins/Hoge/tests/bootstrap.php
(new \Migrations\TestSuite\Migrator())->run(['plugin' => 'Hoge'])
これだと以下のようなエラーが出て動かないので、
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_basercms.sites' doesn't exist

(new \Migrations\TestSuite\Migrator())->runMany([
    ['plugin' => 'BaserCore'],
    ['plugin' => 'BcBlog'],
    ['plugin' => 'BcContentLink'],
    ['plugin' => 'BcCustomContent'],
    ['plugin' => 'BcEditorTemplate'],
    ['plugin' => 'BcFavorite'],
    ['plugin' => 'BcMail'],
    ['plugin' => 'BcSearchIndex'],
    ['plugin' => 'BcThemeConfig'],
    ['plugin' => 'BcThemeFile'],
    ['plugin' => 'BcUploader'],
    ['plugin' => 'BcWidgetArea'],
    ['plugin' => 'Hoge']
]);

こんな感じで動いてます。
(必要なのがどれなのか調べてないので、とりあえず/tests/bootstrap.phpにあったものを丸っとコピーしてます。)
これも冗長というか、こんなもんなのかな?とモヤモヤしているところです。

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 bootstrapは、自分が作ったプラグインだけ定義する感じです

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_basercms.sites' doesn't exist

このログが出るのがおかしいのですが、このログの詳細を貼って頂くことはできますか?
どこから呼び出されているのか知りたい

from bcbake.

binbin4649 avatar binbin4649 commented on July 20, 2024

@ryuring
こんな感じです。

1) DubOgp\Test\TestCase\Model\Table\DubOgpConfigsTableTest::testValidationDefault
Cake\Database\Exception\DatabaseException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_basercms.sites' doesn't exist

/var/www/html/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:160
/var/www/html/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:118
/var/www/html/vendor/cakephp/cakephp/src/ORM/Table.php:521
/var/www/html/vendor/cakephp/cakephp/src/ORM/Query.php:290
/var/www/html/vendor/cakephp/cakephp/src/ORM/Query.php:184
/var/www/html/vendor/cakephp/cakephp/src/ORM/Table.php:1700
/var/www/html/vendor/cakephp/cakephp/src/ORM/Table.php:1255
/var/www/html/plugins/baser-core/src/Plugin.php:201
/var/www/html/plugins/baser-core/src/Plugin.php:156
/var/www/html/vendor/cakephp/cakephp/src/Http/BaseApplication.php:182
/var/www/html/plugins/baser-core/src/TestSuite/BcTestCase.php:194
/var/www/html/plugins/DubOgp/tests/TestCase/Model/Table/DubOgpConfigsTableTest.php:46
/var/www/html/vendor/bin/phpunit:122

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_basercms.sites' doesn't exist

/var/www/html/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php:39
/var/www/html/vendor/cakephp/cakephp/src/Database/Connection.php:329
/var/www/html/vendor/cakephp/cakephp/src/Core/Retry/CommandRetry.php:70
/var/www/html/vendor/cakephp/cakephp/src/Database/Connection.php:332
/var/www/html/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:158
/var/www/html/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:118
/var/www/html/vendor/cakephp/cakephp/src/ORM/Table.php:521
/var/www/html/vendor/cakephp/cakephp/src/ORM/Query.php:290
/var/www/html/vendor/cakephp/cakephp/src/ORM/Query.php:184
/var/www/html/vendor/cakephp/cakephp/src/ORM/Table.php:1700
/var/www/html/vendor/cakephp/cakephp/src/ORM/Table.php:1255
/var/www/html/plugins/baser-core/src/Plugin.php:201
/var/www/html/plugins/baser-core/src/Plugin.php:156
/var/www/html/vendor/cakephp/cakephp/src/Http/BaseApplication.php:182
/var/www/html/plugins/baser-core/src/TestSuite/BcTestCase.php:194
/var/www/html/plugins/DubOgp/tests/TestCase/Model/Table/DubOgpConfigsTableTest.php:46
/var/www/html/vendor/bin/phpunit:122

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 ありがとうございます。ようやく再現できました。
ユニットテストのクラスについて、BcTestCase を継承してと伝えましたが、これが原因のようです。
Cake\TestSuite\TestCase を継承して実行してみてください。

from bcbake.

binbin4649 avatar binbin4649 commented on July 20, 2024

@ryuring
bootstrap.phpに、runManyを書かなくても動くようになりました。
ありがとうございます!

from bcbake.

ryuring avatar ryuring commented on July 20, 2024

@binbin4649 よかったです!

from bcbake.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.