File tree Expand file tree Collapse file tree 6 files changed +97
-12
lines changed
Expand file tree Collapse file tree 6 files changed +97
-12
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ services:
112112 # Поисковик классов в директориях.
113113 class.collector :
114114 class : Prokl\WpSymfonyRouterBundle\Services\Annotations\SearchAnnotatedClasses
115- arguments : ['%kernel.project_dir%', '% controller.annotations.path%']
115+ arguments : ['%controller.annotations.path%']
116116
117117 # Проверка роутов на существование контроллеров.
118118 router.checker.exists :
Original file line number Diff line number Diff line change 1717 */
1818class SearchAnnotatedClasses
1919{
20- /** @var array|null $paths Пути, где искать классы. */
20+ /**
21+ * @var array|null $paths Пути, где искать классы. Указываются с DOCUMENT_ROOT.
22+ */
2123 private $ paths ;
2224
23- /** @var array $classes Результат. Классы. */
25+ /**
26+ * @var array $classes Результат. Классы.
27+ */
2428 private $ classes = [];
25- /** @var string $documentRoot DOCUMENT_ROOT */
26- private $ documentRoot ;
2729
2830 /**
2931 * SearchAnnotatedClasses constructor.
3032 *
31- * @param string $documentRoot DOCUMENT_ROOT.
3233 * @param array|null $paths Пути, где искать классы.
3334 */
3435 public function __construct (
35- string $ documentRoot ,
3636 ?array $ paths = []
3737 ) {
3838 $ this ->paths = $ paths ;
39- $ this ->documentRoot = $ documentRoot ;
4039 }
4140
4241 /**
@@ -52,10 +51,10 @@ public function collect() : array
5251
5352 $ result = [];
5453 foreach ($ this ->paths as $ path ) {
55- $ result [] = $ this ->listClassesByPath ($ this -> documentRoot . $ path );
54+ $ result [] = $ this ->listClassesByPath ($ path );
5655 }
5756
58- $ result = collect ( $ result)-> flatten ()-> toArray () ;
57+ $ result = ( array ) $ result[ 0 ] ;
5958
6059 $ this ->classes = array_merge ($ this ->classes , $ result );
6160
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Prokl \WpSymfonyRouterBundle \Tests \Cases ;
4+
5+ use Prokl \TestingTools \Base \BaseTestCase ;
6+ use Prokl \WpSymfonyRouterBundle \Services \Annotations \SearchAnnotatedClasses ;
7+
8+ /**
9+ * Class AgnosticRoutesLoaderTest
10+ * @package Prokl\BitrixSymfonyRouterBundle\Tests
11+ * @coversDefaultClass SearchAnnotatedClasses
12+ *
13+ * @since 08.08.2021
14+ */
15+ class SearchAnnotatedClassesTest extends BaseTestCase
16+ {
17+ /**
18+ * @var SearchAnnotatedClasses $obTestObject Тестируемый объект.
19+ */
20+ protected $ obTestObject ;
21+
22+ /**
23+ * @var string $paths
24+ */
25+ private $ paths = [__DIR__ . '/../Fixture/AnnotatedClass ' ];
26+
27+ /**
28+ * @inheritdoc
29+ */
30+ protected function setUp (): void
31+ {
32+ parent ::setUp ();
33+
34+ $ this ->obTestObject = new SearchAnnotatedClasses ($ this ->paths );
35+
36+ }
37+
38+ /**
39+ * collect().
40+ *
41+ * @return void
42+ */
43+ public function testCollect () : void
44+ {
45+ $ result = $ this ->obTestObject ->collect ();
46+
47+ $ this ->assertNotEmpty ($ result );
48+ $ this ->assertCount (2 , $ result );
49+ }
50+
51+ /**
52+ * collect(). Пустая переменная controller.annotations.path.
53+ *
54+ * @return void
55+ */
56+ public function testCollectEmptyParams () : void
57+ {
58+ $ this ->obTestObject = new SearchAnnotatedClasses ([]);
59+ $ result = $ this ->obTestObject ->collect ();
60+
61+ $ this ->assertEmpty ($ result );
62+ }
63+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Fixture \AnnotatedClass ;
4+
5+ /**
6+ * Class AnnotatedClass
7+ * @package Fixture\AnnotatedClass
8+ */
9+ class AnnotatedClass
10+ {
11+
12+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Fixture \AnnotatedClass ;
4+
5+ /**
6+ * Class SimpleClass
7+ * @package Fixture\AnnotatedClass
8+ */
9+ class SimpleClass
10+ {
11+
12+ }
Original file line number Diff line number Diff line change 3838 "symfony/event-dispatcher" : " ^4.4 || ^5.0" ,
3939 "symfony/property-access" : " ^4.4 || ^5.0" ,
4040 "symfony/expression-language" : " ^4.4 || ^5.0" ,
41- "symfony/serializer" : " ^4.4 || ^5.0" ,
42- "illuminate/support" : " ~5 | ~6 | ~7 | ~8"
41+ "symfony/serializer" : " ^4.4 || ^5.0"
4342 },
4443 "require-dev" : {
4544 "proklung/wordpress-test-build" : " ^1.2"
You can’t perform that action at this time.
0 commit comments