Skip to content

Commit 9b3d03b

Browse files
committed
Тесты.
1 parent 3482b73 commit 9b3d03b

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

Tests/Cases/SampleAjaxControllerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Prokl\WpSymfonyRouterBundle\Tests\Cases;
44

5+
use Prokl\TestingTools\Tools\Container\BuildContainer;
56
use Prokl\WordpressCi\Base\WordpressableAjaxTestCase;
67

78
/**
@@ -10,16 +11,41 @@
1011
*/
1112
class SampleAjaxControllerTest extends WordpressableAjaxTestCase
1213
{
14+
/**
15+
* @inheritDoc
16+
*/
1317
protected function setUp() : void
1418
{
1519
parent::setup();
1620
wp_set_current_user( 1 );
21+
22+
$this->container = static::$testContainer = BuildContainer::getTestContainer(
23+
[
24+
'test_container.yaml'
25+
],
26+
'/../../../../Tests/Fixture'
27+
);
28+
29+
$this->container->get('wp_ajax.initializer');
1730
}
1831

32+
/**
33+
* @return void
34+
*/
1935
public function testAction() : void
2036
{
2137
$this->_handleAjax('examples_wp');
2238
$result = $this->_last_response;
2339
$this->assertSame('OK', $result);
2440
}
41+
42+
/**
43+
* @return void
44+
*/
45+
public function testActionInvalid() : void
46+
{
47+
$this->_handleAjax('examples_invalid');
48+
$result = $this->_last_response;
49+
$this->assertSame('', $result);
50+
}
2551
}

Tests/Fixture/test_container.yaml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,37 @@ services:
1010
public: true
1111

1212
Prokl\WpSymfonyRouterBundle\Tests\Fixture\FixtureAjaxController: ~
13-
Prokl\WpSymfonyRouterBundle\Tests\Fixture\FixtureAjaxControllerInvoke: ~
13+
Prokl\WpSymfonyRouterBundle\Tests\Fixture\FixtureAjaxControllerInvoke: ~
14+
15+
routing.resolver:
16+
class: Symfony\Component\Config\Loader\LoaderResolver
17+
arguments:
18+
- ['@routing.loader.yml']
19+
20+
file_locator:
21+
class: Symfony\Component\Config\FileLocator
22+
23+
routing.loader.yml:
24+
class: Symfony\Component\Routing\Loader\YamlFileLoader
25+
arguments: ['@file_locator']
26+
tags:
27+
- { name: routing.loader }
28+
29+
wp_ajax.loader:
30+
public: true
31+
class: Symfony\Component\Routing\RouteCollection
32+
factory: ['@routing.loader', 'load']
33+
arguments: ['%kernel.project_dir%/../../../Tests/Fixture/wp_routes.yaml']
34+
35+
wp_ajax.initializer:
36+
class: Prokl\WpSymfonyRouterBundle\Services\NativeAjax\WpAjaxInitializer
37+
arguments: ['@wp_ajax.loader', '@service_container']
38+
39+
routing.loader:
40+
class: Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader
41+
arguments:
42+
- '@routing.resolver'
43+
- []
44+
- []
45+
46+
Prokl\WpSymfonyRouterBundle\Tests\Fixture\Controller\SampleAjaxController: ~

Tests/Fixture/wp_routes.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
examples_wp: # Action роута
2+
path: '' # Игнор
3+
methods: [GET, POST]
4+
controller: 'Prokl\WpSymfonyRouterBundle\Tests\Fixture\Controller\SampleAjaxController::action'
5+
defaults:
6+
_public: true
7+

0 commit comments

Comments
 (0)