-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ClassesIn & MethodsIn delegates
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/test/php/web/frontend/unittest/ClassesInTest.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php namespace web\frontend\unittest; | ||
|
||
use unittest\TestCase; | ||
use web\frontend\ClassesIn; | ||
use lang\reflect\Package; | ||
|
||
class ClassesInTest extends TestCase { | ||
|
||
#[@test] | ||
public function can_create_with_string() { | ||
new ClassesIn('web.frontend.unittest.actions'); | ||
} | ||
|
||
#[@test] | ||
public function can_create_with_package() { | ||
new ClassesIn(Package::forName('web.frontend.unittest.actions')); | ||
} | ||
|
||
#[@test] | ||
public function patterns_sorted_by_length() { | ||
$delegates= new ClassesIn('web.frontend.unittest.actions'); | ||
$this->assertEquals( | ||
[ | ||
'#get/blogs/(?<category>[^/]+)/(?<id>[0-9]+)$#', | ||
'#get/users/(?<id>[^/]+)/avatar$#', | ||
'#get/users/(?<id>[^/]+)$#', | ||
'#post/users$#', | ||
'#get/users$#', | ||
'#get.+$#' | ||
], | ||
array_keys($delegates->patterns) | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/php/web/frontend/unittest/MethodsInTest.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php namespace web\frontend\unittest; | ||
|
||
use unittest\TestCase; | ||
use web\frontend\MethodsIn; | ||
use web\frontend\unittest\actions\Users; | ||
|
||
class MethodsInTest extends TestCase { | ||
|
||
#[@test] | ||
public function can_create() { | ||
new MethodsIn(new Users()); | ||
} | ||
|
||
#[@test] | ||
public function patterns_sorted_by_length() { | ||
$delegates= new MethodsIn(new Users()); | ||
$this->assertEquals( | ||
[ | ||
'#get/users/(?<id>[^/]+)/avatar$#', | ||
'#get/users/(?<id>[^/]+)$#', | ||
'#post/users$#', | ||
'#get/users$#', | ||
], | ||
array_keys($delegates->patterns) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace web\frontend\unittest\actions; | ||
|
||
class Home { | ||
|
||
#[@get] | ||
public function get() { | ||
return ['home' => true]; | ||
} | ||
} |