質問 > 管理機能 > ファンクショナルテストでのclient->request()のuriの書き方について |
管理機能
フラット表示 | 前のトピック | 次のトピック |
投稿者 | スレッド |
---|---|
xaiam |
投稿日時: 2020/7/1 17:34
対応状況: −−−
|
新米 登録日: 2020/6/10 居住地: 投稿: 10 |
ファンクショナルテストでのclient->request()のuriの書き方について ▼テンプレート
[EC-CUBE] EC-CUBEのバージョン、新規インストールかアップデートか、等 [レンタルサーバ] [OS] macos catalina [PHP] 7.2 [データベース] MySQL 5.7.28 [WEBサーバ] Symfony Local Server v4.16.1 [ブラウザ] chrome 最新 [導入プラグインの有無] [カスタマイズの有無] entityをcustomizeで作成、そのadmin用のコントローラーとtwigも作成済み [現象] 現在adminページを作成し終え、そのページが正常に表示されるかのファンクショナルテストを行おうとしています。 公式ドキュメントにテストの方法についての説明がなかったようなのでとりあえずプロジェクトルート直下のtests/Customize/フォルダに例としてSampleControllerTest.phpを作成しました。 そしてその中に下記のメソッドを記述しましたが`bin/phpunit [コントローラーまでのパス]`コマンドを実行してもエラーとなり上手く行きません エラー文は次の通りです。 -> % bin/phpunit /Users/x/Projects/aaa-shop-eccube4/tests/Customize/SampleControllerTest.php #!/usr/bin/env php PHPUnit 6.5.14 by Sebastian Bergmann and contributors. Testing xxx\aaa\Tests\Customize\SampleControllerTest E 1 / 1 (100%) Time: 839 ms, Memory: 32.00MB There was 1 error: 1) xxx\aaaShop\Tests\Customize\SampleControllerTest::testIndex Error: Call to a member function request() on null そして該当のSampleControllerTestはこちらです。 use Symfony\Bundle\FrameworkBundle\Client; use xxx\aaaShop\Tests\Eccube\Controller\AbstractTestCase; class SampleControllerTest extends AbstractTestCase { /** * @var Client */ protected $client; public function testIndex() { $crawler = $this->client->request('GET', '/sample/'); $this->assertStatusCode(200, $this->client); $h2Nodes = $crawler->filter('h2.c-pageTitle__title'); dump($h2Nodes);exit(); $this->assertNotEmpty($h2Nodes, 'h2が表示されている'); $this->assertCount(1, $h2Nodes, 'h2は一つだけ'); $this->assertEquals( 'ggg一覧', $h2Nodes->eq(0)->text(), 'h1に「ggg一覧」という文字列を含む' ); } } このうちの $crawler = $this->client->request('GET', '/sample/'); のrequest()の第二引数の書き方が間違っているのでしょうか? またSampleController::index()のrouteはこちらです /** * @Route("/%eccube_admin_route%/sample") */ class SampleController extends AbstractController { /** * @Route("/", name="admin_sample_index") * @Template("@admin/sample/sample.html.twig") */ public function index(Request $request) よろしくお願いします。 |
フラット表示 | 前のトピック | 次のトピック |
題名 | 投稿者 | 日時 |
---|---|---|
» ファンクショナルテストでのclient->request()のuriの書き方について | xaiam | 2020/7/1 17:34 |
Re: ファンクショナルテストでのclient->request()のuriの書き方について | xaiam | 2020/7/1 18:28 |