├── tests ├── common │ ├── 009Test.phtml │ ├── 053Test_3.inc │ ├── 049Test_6.inc │ ├── 049Test_5.inc │ ├── 048Test_5.inc │ ├── 034Test.inc │ ├── 067Test_2.inc │ ├── 050Test_2.inc │ ├── 061Test_2.inc │ ├── 079Test_2.inc │ ├── 083Test_1.inc │ ├── multi-section.ini │ ├── 053Test_2.inc │ ├── 059Test_1.inc │ ├── 049Test_1.inc │ ├── 050Test_1.inc │ ├── 060Test_2.inc │ ├── 048Test_1.inc │ ├── 053Test_1.inc │ ├── 061Test_1.inc │ ├── 049Test_4.inc │ ├── 067Test_1.inc │ ├── 059Test_2.inc │ ├── 079Test_1.inc │ ├── 048Test_4.inc │ ├── 048Test_2.inc │ ├── configs │ │ ├── system.ini │ │ ├── simple.ini │ │ ├── p010_simple.ini │ │ ├── p032_simple.ini │ │ ├── p044_simple.ini │ │ └── p055_simple.ini │ ├── 049Test_2.inc │ ├── 060Test_1.inc │ ├── 048Test_3.inc │ ├── 049Test_3.inc │ └── build.inc ├── bootstrap.php ├── P014Test.php ├── P001Test.php ├── P017Test.php ├── P035Test.php ├── P047Test.php ├── Base.php ├── P071Test.php ├── P085Test.php ├── P015Test.php ├── P040Test.php ├── P068Test.php ├── P081Test.php ├── P0bug61493Test.php ├── P009Test.php ├── P004Test.php ├── P034Test.php ├── P032Test.php ├── P029Test.php ├── P028Test.php ├── P044Test.php ├── P056Test.php ├── P057Test.php ├── P058Test.php ├── P055Test.php ├── P030Test.php ├── P054Test.php ├── P0issue134Test.php ├── P079Test.php ├── P021Test.php ├── P074Test.php ├── P070Test.php ├── P082Test.php ├── P031Test.php ├── P051Test.php ├── P019Test.php ├── P026Test.php ├── P066Test.php ├── P038Test.php ├── P011Test.php ├── P083Test.php ├── P046Test.php ├── P062Test.php ├── P084Test.php ├── P006Test.php ├── P050Test.php ├── P037Test.php ├── P024Test.php ├── P012Test.php ├── P075Test.php ├── P078Test.php ├── P060Test.php ├── P025Test.php ├── P069Test.php ├── P061Test.php ├── P065Test.php ├── P039Test.php ├── P059Test.php ├── P073Test.php ├── P077Test.php ├── P067Test.php ├── P005Test.php ├── P027Test.php ├── P042Test.php ├── P016Test.php ├── P053Test.php ├── P022Test.php ├── P020Test.php ├── P076Test.php ├── P045Test.php ├── P049Test.php ├── P003Test.php ├── P063Test.php ├── P023Test.php ├── P064Test.php ├── P052Test.php ├── P048Test.php ├── P0bug62702Test.php ├── P072Test.php ├── P018Test.php ├── P0bug63438Test.php ├── P007Test.php ├── P008Test.php ├── P002Test.php ├── P033Test.php ├── P041Test.php └── P036Test.php ├── docs ├── logo.png ├── yaf_php_auto.gif └── yaf_php_tip.gif ├── .gitignore ├── psr0 ├── exception │ ├── TypeError.php │ ├── LoadFailed.php │ ├── RouterFailed.php │ ├── DispatchFailed.php │ ├── StartupError.php │ └── LoadFailed │ │ ├── Action.php │ │ ├── Module.php │ │ ├── View.php │ │ └── Controller.php ├── responses │ └── Cli.php ├── Exception.php ├── Bootstrap.php ├── Action.php ├── view │ └── Interface.php ├── Registry.php ├── Config.php ├── Plugin.php └── routes │ ├── Supervar.php │ ├── Simple.php │ └── Interface.php ├── psr4 ├── exception │ ├── LoadFailed.php │ ├── TypeError.php │ ├── RouterFailed.php │ ├── StartupError.php │ ├── DispatchFailed.php │ └── LoadFailed │ │ ├── View.php │ │ ├── Action.php │ │ ├── Module.php │ │ └── Controller.php ├── responses │ └── Cli.php ├── Bootstrap.php ├── Action.php ├── view │ └── Interface.php ├── Exception.php ├── Registry.php ├── Config.php ├── Plugin.php └── routes │ ├── Supervar.php │ └── Interface.php ├── .travis.yml ├── composer.json ├── phpunit.xml ├── LICENSE └── README.md /tests/common/009Test.phtml: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /tests/common/053Test_3.inc: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/common/049Test_6.inc: -------------------------------------------------------------------------------- 1 | catched: 2 | -------------------------------------------------------------------------------- /tests/common/049Test_5.inc: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinggaozhen/yaf-php-doc/HEAD/docs/logo.png -------------------------------------------------------------------------------- /tests/common/048Test_5.inc: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | \.idea 2 | vendor 3 | composer\.lock 4 | *\.out 5 | *\.swp 6 | test 7 | tmp_build 8 | -------------------------------------------------------------------------------- /docs/yaf_php_auto.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinggaozhen/yaf-php-doc/HEAD/docs/yaf_php_auto.gif -------------------------------------------------------------------------------- /docs/yaf_php_tip.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yinggaozhen/yaf-php-doc/HEAD/docs/yaf_php_tip.gif -------------------------------------------------------------------------------- /tests/common/034Test.inc: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /tests/common/067Test_2.inc: -------------------------------------------------------------------------------- 1 | _view->name = 'custom view'; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/common/059Test_1.inc: -------------------------------------------------------------------------------- 1 | returnResponse(true); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/common/049Test_1.inc: -------------------------------------------------------------------------------- 1 | _view->msg = $exception->getMessage(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/common/050Test_1.inc: -------------------------------------------------------------------------------- 1 | returnResponse(true); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/common/060Test_2.inc: -------------------------------------------------------------------------------- 1 | _view->obj = $obj; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/common/048Test_1.inc: -------------------------------------------------------------------------------- 1 | getMessage()); 8 | return false; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | setView(new SimpleView(YAF_TEST_APPLICATION_PATH . '/views')); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/common/061Test_1.inc: -------------------------------------------------------------------------------- 1 | forward('dummy'); 8 | } 9 | 10 | public function dummyAction() 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /psr0/exception/TypeError.php: -------------------------------------------------------------------------------- 1 | 'actions/sub.php', 7 | ]; 8 | 9 | public function indexAction() 10 | { 11 | var_dump($this->forward('sub')); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /psr4/exception/LoadFailed.php: -------------------------------------------------------------------------------- 1 | flushInstantly(true); 8 | } 9 | 10 | public function indexAction() 11 | { 12 | var_dump($this->_view->getScriptPath()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/common/079Test_1.inc: -------------------------------------------------------------------------------- 1 | registerLocalNamespace('Test'); 12 | \Yaf\Registry::set('test', new Test079()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: php 3 | 4 | php: 5 | - 7.1 6 | - 7.2 7 | 8 | cache: 9 | directories: 10 | - $HOME/.composer/cache 11 | 12 | 13 | before_install: 14 | - travis_retry composer self-update 15 | 16 | install: 17 | - composer install 18 | 19 | before_script: 20 | - composer test --coverage-clover=coverage.xml --configuration=phpunit.xml 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/P014Test.php: -------------------------------------------------------------------------------- 1 | assertFalse(extension_loaded("yaf")); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/common/048Test_4.inc: -------------------------------------------------------------------------------- 1 | application->dispatcher->catchException); 15 | $this->getView()->assignRef('ref', $value); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/P017Test.php: -------------------------------------------------------------------------------- 1 | getConfig()); 10 | } 11 | 12 | /** 13 | * @param \Yaf\Dispatcher $dispatcher 14 | * @throws Exception 15 | */ 16 | public function _initPlugin(\Yaf\Dispatcher $dispatcher) 17 | { 18 | $dispatcher->registerPlugin(new TestPlugin()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/P035Test.php: -------------------------------------------------------------------------------- 1 | markTestSkipped(); 23 | } 24 | 25 | public function tearDown() 26 | { 27 | parent::setUp(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /psr4/Bootstrap.php: -------------------------------------------------------------------------------- 1 | assertFalse(extension_loaded("yaf")); 20 | } 21 | 22 | /** 23 | * @param $object 24 | * @param string $property 25 | * @return mixed 26 | * @throws \ReflectionException 27 | */ 28 | public function proxyGetProperty($object, $property) 29 | { 30 | return \YP\internalPropertyGet($object, $property); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/P071Test.php: -------------------------------------------------------------------------------- 1 | assertFalse($new->valid()); 26 | } 27 | 28 | public function tearDown() 29 | { 30 | parent::setUp(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/P085Test.php: -------------------------------------------------------------------------------- 1 | getRaw(); 26 | 27 | $this->markTestSkipped(); 28 | } 29 | 30 | public function tearDown() 31 | { 32 | parent::setUp(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/common/049Test_2.inc: -------------------------------------------------------------------------------- 1 | getConfig()); 10 | } 11 | 12 | /** 13 | * @param \Yaf\Dispatcher $dispatcher 14 | * @throws Exception 15 | */ 16 | public function _initPlugin(\Yaf\Dispatcher $dispatcher) 17 | { 18 | $dispatcher->registerPlugin(new TestPlugin()); 19 | } 20 | 21 | public function _initReturn(\Yaf\Dispatcher $dispatcher) 22 | { 23 | $dispatcher->returnResponse(true); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/common/060Test_1.inc: -------------------------------------------------------------------------------- 1 | setErrorHandler(['Bootstrap', 'errorHandler']); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/P015Test.php: -------------------------------------------------------------------------------- 1 | assertTrue($previous === $exception->getPrevious()); 24 | $this->assertSame('Exception', $exception->getMessage()); 25 | $this->assertSame(100, $exception->getPrevious()->getCode()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/P040Test.php: -------------------------------------------------------------------------------- 1 | render(null); 25 | $view->render(0); 26 | $view->render(true); 27 | 28 | $this->assertTrue(true); 29 | } 30 | 31 | public function tearDown() 32 | { 33 | parent::setUp(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/P068Test.php: -------------------------------------------------------------------------------- 1 | markTestSkipped('multi ini parse incomplete'); 19 | } 20 | 21 | /** 22 | * @throws Exception 23 | * @throws \Yaf\Exception\TypeError 24 | */ 25 | public function test() 26 | { 27 | $config = new Ini(__DIR__ . '/common/multi-section.ini'); 28 | print_r($config->toArray()); 29 | } 30 | 31 | public function tearDown() 32 | { 33 | parent::setUp(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/P081Test.php: -------------------------------------------------------------------------------- 1 | setBody($string); 27 | $response->setBody($string); 28 | $this->assertSame('Jason is a good boy', $response->getBody()); 29 | } 30 | 31 | public function tearDown() 32 | { 33 | parent::setUp(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/P0bug61493Test.php: -------------------------------------------------------------------------------- 1 | 'bar', 26 | ), false); 27 | 28 | unset($config['foo']); 29 | $this->assertSame([], \YP\internalPropertyGet($config, '_config')); 30 | } 31 | 32 | public function tearDown() 33 | { 34 | parent::setUp(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/P009Test.php: -------------------------------------------------------------------------------- 1 | assign('name', $value); 26 | unset($value); 27 | 28 | $this->assertSame('laruence', $view->get('name')); 29 | $this->assertSame(6, strlen($view->render(__DIR__ . '/common/009Test.phtml'))); 30 | $this->assertSame('laruence', $view->name); 31 | $this->assertNull($view->noexists); 32 | } 33 | 34 | public function tearDown() 35 | { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yinggaozhen/yaf-php", 3 | "description": "Yaf PHP version", 4 | "type": "yaf-php", 5 | "version": "1.0.0", 6 | "minimum-stability": "dev", 7 | "homepage": "https://github.com/yinggaozhen/yaf-php", 8 | "require" : { 9 | "php" : ">=7.1" 10 | }, 11 | "authors": [ 12 | { 13 | "name": "Gaozhen Ying", 14 | "email": "yinggaozhen@hotmail.com" 15 | } 16 | ], 17 | "autoload": { 18 | "psr-4": { 19 | }, 20 | "classmap": [ 21 | "./" 22 | ], 23 | "files": [ 24 | "./Yaf.php", 25 | "./psr4/Exception.php", 26 | "./psr4/routes/Interface.php" 27 | ] 28 | }, 29 | "scripts": { 30 | "test": "phpunit" 31 | }, 32 | "require-dev": { 33 | "phpunit/phpunit": "^6.0" 34 | }, 35 | "repositories": { 36 | "packagist": { 37 | "type": "composer", 38 | "url": "https://packagist.phpcomposer.com" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/P004Test.php: -------------------------------------------------------------------------------- 1 | assertSame('Ageli Platform', Yaf_Registry::get('name')); 24 | $this->assertTrue(Yaf_Registry::has('name')); 25 | 26 | //--------------------------------------- 27 | 28 | $name = 'name'; 29 | Yaf_Registry::del($name); 30 | 31 | $this->assertNull(Yaf_Registry::get($name)); 32 | $this->assertFalse(Yaf_Registry::has($name)); 33 | } 34 | 35 | public function tearDown() 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/P034Test.php: -------------------------------------------------------------------------------- 1 | assign('entry', ['a', 'b', 'c']); 27 | $actual = $view->eval($tpl, ['name' => 'template']); 28 | 29 | $expect = <<assertSame($expect, $actual); 37 | } 38 | 39 | public function tearDown() 40 | { 41 | parent::setUp(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/P032Test.php: -------------------------------------------------------------------------------- 1 | assertSame([ 30 | 'env' => 'bar', 31 | 'ini' => '', 32 | 'const' => 'Dummy' 33 | ], internalPropertyGet($config, '_config')); 34 | } 35 | 36 | public function tearDown() 37 | { 38 | parent::setUp(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/P029Test.php: -------------------------------------------------------------------------------- 1 | assign('a', 'b'); 25 | $view->assign('b', 'a'); 26 | $this->assertSame('b', $view->get('a')); 27 | $this->assertSame([ 28 | 'a' => 'b', 29 | 'b' => 'a' 30 | ], $view->get()); 31 | 32 | $view->clear('b'); 33 | $this->assertSame([ 34 | 'a' => 'b' 35 | ], $view->get()); 36 | $view->clear(); 37 | $this->assertSame([], $view->get()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/P028Test.php: -------------------------------------------------------------------------------- 1 | assign('name', 'laruence'); 29 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml'; 30 | 31 | file_put_contents($tpl, <<assertSame('okey', $view->render($tpl)); 36 | } 37 | 38 | public function tearDown() 39 | { 40 | shutdown(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/P044Test.php: -------------------------------------------------------------------------------- 1 | assertSame('Yaf\Dispatcher', get_class($b)); 32 | } 33 | 34 | public function tearDown() 35 | { 36 | parent::setUp(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /psr4/Action.php: -------------------------------------------------------------------------------- 1 | _controller; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/P056Test.php: -------------------------------------------------------------------------------- 1 | throwException(true); 27 | $this->assertTrue(Dispatcher::getInstance()->throwException()); 28 | Dispatcher::getInstance()->throwException(false); 29 | $this->assertFalse(Dispatcher::getInstance()->throwException()); 30 | } 31 | 32 | public function tearDown() 33 | { 34 | parent::setUp(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/P057Test.php: -------------------------------------------------------------------------------- 1 | catchException(true); 27 | $this->assertTrue(Dispatcher::getInstance()->catchException()); 28 | Dispatcher::getInstance()->catchException(false); 29 | $this->assertFalse(Dispatcher::getInstance()->catchException()); 30 | } 31 | 32 | public function tearDown() 33 | { 34 | parent::setUp(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/P058Test.php: -------------------------------------------------------------------------------- 1 | flushInstantly(true); 27 | $this->assertTrue(Dispatcher::getInstance()->flushInstantly()); 28 | Dispatcher::getInstance()->flushInstantly(false); 29 | $this->assertFalse(Dispatcher::getInstance()->flushInstantly()); 30 | } 31 | 32 | public function tearDown() 33 | { 34 | parent::setUp(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /psr0/Action.php: -------------------------------------------------------------------------------- 1 | _controller; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/P055Test.php: -------------------------------------------------------------------------------- 1 | autoRender(true); 28 | $this->assertTrue(Dispatcher::getInstance()->autoRender()); 29 | Dispatcher::getInstance()->autoRender(false); 30 | $this->assertFalse(Dispatcher::getInstance()->autoRender()); 31 | } 32 | 33 | public function tearDown() 34 | { 35 | parent::setUp(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | ./ 20 | 21 | tests 22 | vendor 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/P030Test.php: -------------------------------------------------------------------------------- 1 | assertTrue( 32 | strncmp( 33 | "There is no section 'ex' in", 34 | $e->getMessage(), 35 | strlen("There is no section 'ex' in") 36 | ) === 0 37 | ); 38 | } 39 | 40 | $this->assertTrue($exception); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/P054Test.php: -------------------------------------------------------------------------------- 1 | assertTrue(stripos($e->getMessage(), 'Argument is not a valid ini file ') !== false); 27 | } 28 | $this->assertTrue($exception); 29 | 30 | $request = new Simple(null); 31 | $this->assertFalse($request->isOptions()); 32 | 33 | $config = new Simple([]); 34 | $config->key(); 35 | $this->assertSame('okey', 'okey'); 36 | } 37 | 38 | public function tearDown() 39 | { 40 | parent::setUp(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/P0issue134Test.php: -------------------------------------------------------------------------------- 1 | 'index', 28 | 'action' => 'detail', 29 | 'module' => 'kfc' 30 | ] 31 | ); 32 | $router->addRoute('kfc/index/detail', $route); 33 | $this->assertSame('/detail/1', $router->getRoute('kfc/index/detail')->assemble([ 34 | ':id' => '1', 35 | ] 36 | )); 37 | } 38 | 39 | public function tearDown() 40 | { 41 | parent::setUp(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/common/configs/simple.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=APPLICATION_PATH "/applcation" 3 | name = "base" 4 | array.1 = 1 5 | 5=6 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${FOO} 40 | ini=${yaf.directory} 41 | const=FOO 42 | 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Gaozhen Ying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/common/configs/p010_simple.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=P010_APPLICATION_PATH "/applcation" 3 | name = "base" 4 | array.1 = 1 5 | 5=6 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${FOO} 40 | ini=${yaf.directory} 41 | const=FOO 42 | 43 | -------------------------------------------------------------------------------- /tests/common/configs/p032_simple.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=APPLICATION_PATH "/applcation" 3 | name = "base" 4 | array.1 = 1 5 | 5=6 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${P032FOO} 40 | ini=${yaf.directory} 41 | const=P032FOO 42 | 43 | -------------------------------------------------------------------------------- /tests/common/configs/p044_simple.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=P044_APPLICATION_PATH "/applcation" 3 | name = "base" 4 | array.1 = 1 5 | 5=6 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${P032FOO} 40 | ini=${yaf.directory} 41 | const=P032FOO 42 | 43 | -------------------------------------------------------------------------------- /tests/common/configs/p055_simple.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=P055_APPLICATION_PATH "/applcation" 3 | name = "base" 4 | array.1 = 1 5 | 5=6 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${P055FOO} 40 | ini=${yaf.directory} 41 | const=P055FOO 42 | 43 | -------------------------------------------------------------------------------- /tests/P079Test.php: -------------------------------------------------------------------------------- 1 | [ 28 | 'directory' => YAF_TEST_APPLICATION_PATH, 29 | ], 30 | ]; 31 | 32 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/079Test_1.inc')); 33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/library/Test.php', file_get_contents(__DIR__ . '/common/079Test_2.inc')); 34 | 35 | $app = new \Yaf\Application($config); 36 | $app->bootstrap(); 37 | } 38 | 39 | public function tearDown() 40 | { 41 | parent::setUp(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/common/048Test_3.inc: -------------------------------------------------------------------------------- 1 | getDispatcher()->setErrorHandler('error_handler', E_ALL); 36 | $app->run(); 37 | } 38 | 39 | public function tearDown() 40 | { 41 | parent::tearDown(); 42 | define('APPLICATION_PATH', null); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/P074Test.php: -------------------------------------------------------------------------------- 1 | addRoute('simple', $route); 29 | 30 | $this->assertSame('?m=yafmodule&c=yafcontroller&a=yafaction&tkey1=tval1&tkey2=tval2', $router->getRoute('simple')->assemble([ 31 | ':a' => 'yafaction', 32 | 'tkey' => 'tval', 33 | ':c' => 'yafcontroller', 34 | ':m' => 'yafmodule' 35 | ], 36 | [ 37 | 'tkey1' => 'tval1', 38 | 'tkey2' => 'tval2' 39 | ] 40 | )); 41 | } 42 | 43 | public function tearDown() 44 | { 45 | parent::setUp(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/P070Test.php: -------------------------------------------------------------------------------- 1 | run(); 35 | } 36 | catch (\Exception $e) { 37 | $expection = true; 38 | 39 | // TODO $e->getPrevious()->getMessage() 40 | $this->assertSame('Expects a path to *.ini configuration file as parameter', $e->getMessage()); 41 | } 42 | 43 | $this->assertTrue($expection); 44 | } 45 | 46 | public function tearDown() 47 | { 48 | parent::setUp(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/P082Test.php: -------------------------------------------------------------------------------- 1 | assign('name', 'laruence'); 29 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml'; 30 | 31 | file_put_contents($tpl, <<render($tpl); 39 | $actual = ob_get_contents(); 40 | ob_end_clean(); 41 | 42 | $this->assertTrue(stripos(error_get_last()['message'], 'Undefined variable: tpl') !== false); 43 | $this->assertSame('laruence', $actual); 44 | } 45 | 46 | public function tearDown() 47 | { 48 | parent::setUp(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/P031Test.php: -------------------------------------------------------------------------------- 1 | [ 26 | 'directory' => realpath(__DIR__), 27 | 'dispatcher' => [ 28 | 'defaultRoute' => [ 29 | 'type' => 'map', 30 | 'delimiter' => '##', 31 | 'controllerPrefer' => 1, 32 | ], 33 | ], 34 | ], 35 | ]; 36 | 37 | $app = new Application($config); 38 | $routes = $app->getDispatcher()->getRouter()->getRoutes()['_default']; 39 | 40 | $this->assertTrue(internalPropertyGet($routes, '_ctl_router')); 41 | $this->assertSame('##', internalPropertyGet($routes, '_delimiter')); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/P051Test.php: -------------------------------------------------------------------------------- 1 | route($x); 31 | 32 | $x = new Route_Static(); 33 | $x->route($x); 34 | 35 | $x = new Rewrite('#^/test#', ['controller' => 'info'], []); 36 | $x->route($x); 37 | 38 | $x = new Supervar('r'); 39 | $x->route($x); 40 | 41 | $x = new Regex('#^/test#', ['controller' => 'info'], []); 42 | $x->route($x); 43 | 44 | $this->assertSame('okey', 'okey'); 45 | } 46 | 47 | public function tearDown() 48 | { 49 | parent::setUp(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/P019Test.php: -------------------------------------------------------------------------------- 1 | addConfig( 28 | [ 29 | [ 30 | 'type' => 'regex', 31 | 'match' => '#^/ap/([^/]*)/*#i', 32 | 'route' => [ 33 | [ 34 | 'action' => 'ap', 35 | ], 36 | ], 37 | 'map' => [ 38 | 1 => 'version', 39 | ] 40 | ] 41 | ] 42 | )->route($request); 43 | 44 | $this->assertSame(0, $router->getCurrentRoute()); 45 | $this->assertSame('1.2', $request->getParam('version')); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/common/build.inc: -------------------------------------------------------------------------------- 1 | setBody('ell') 27 | ->appendBody('o') 28 | ->setBody(' W', 'footer') 29 | ->prependBody('H') 30 | ->appendBody('orld', 'footer'); 31 | 32 | 33 | $this->assertSame('Hello', $response->getBody('content')); 34 | $this->assertSame(' World', $response->getBody('footer')); 35 | $this->assertTrue((bool) internalPropertyGet($response, '_sendheader')); 36 | $this->assertFalse((bool) internalPropertyGet($response, '_response_code')); 37 | $this->assertSame('Hello World', (string) $response); 38 | } 39 | 40 | public function tearDown() 41 | { 42 | parent::tearDown(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/P066Test.php: -------------------------------------------------------------------------------- 1 | addRoute('ap', new Regex("#^/ap/([^/]*)/([^/]*)/*#i", [ 29 | 'action' => 'ap', 30 | ], [ 31 | 1 => 23432, 32 | 2 => null, 33 | ] 34 | ))->route($request); 35 | 36 | $this->assertSame('ap', $router->getCurrentRoute()); 37 | $this->assertNull($request->getParam(1)); 38 | $this->assertSame('ap', $request->getActionName()); 39 | $this->assertNull($request->getControllerName()); 40 | $this->assertNull($request->getParam('name')); 41 | } 42 | 43 | public function tearDown() 44 | { 45 | parent::setUp(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/P038Test.php: -------------------------------------------------------------------------------- 1 | assign('name', 'laruence'); 30 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml'; 31 | 32 | $html = << 37 | HTML; 38 | 39 | $exception = false; 40 | file_put_contents($tpl, $html); 41 | try { 42 | echo $view->render($tpl); 43 | } catch (Error $e) { 44 | $exception = true; 45 | $this->assertSame("syntax error, unexpected '}'", $e->getMessage()); 46 | } 47 | 48 | $this->assertTrue($exception); 49 | } 50 | 51 | public function tearDown() 52 | { 53 | parent::setUp(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/P011Test.php: -------------------------------------------------------------------------------- 1 | addRoute('subdir', new Rewrite('/subdir/:name/:version', [ 30 | 'action' => 'version', 31 | ] 32 | )) 33 | ->addRoute('ap', new Rewrite('/ap/:version/*', [ 34 | 'action' => 'ap', 35 | ] 36 | )) 37 | ->route($request); 38 | 39 | $this->assertSame('ap', $router->getCurrentRoute()); 40 | $this->assertSame('1.2', $request->getParam('version')); 41 | $this->assertSame('ap', $request->getActionName()); 42 | $this->assertNull($request->getControllerName()); 43 | $this->assertSame('value', $request->getParam('name')); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/P083Test.php: -------------------------------------------------------------------------------- 1 | [ 30 | 'directory' => YAF_TEST_APPLICATION_PATH, 31 | ], 32 | ]; 33 | 34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/083Test_1.inc')); 35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', 'okey'); 36 | 37 | $app = new Application($config); 38 | $response = $app->getDispatcher()->returnResponse(true)->dispatch(new Simple('CLI', 'Index', 'Index', 'index')); 39 | $this->assertSame('okey', $response->getBody()); 40 | } 41 | 42 | public function tearDown() 43 | { 44 | parent::setUp(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/P046Test.php: -------------------------------------------------------------------------------- 1 | [ 27 | 'directory' => __DIR__, 28 | 'library' => [ 29 | 'directory' => '/tmp', 30 | 'namespace' => 'Foo', 31 | ], 32 | ], 33 | ]; 34 | 35 | new Application($config); 36 | $loader = Loader::getInstance(); 37 | $this->assertTrue($loader->isLocalName('Foo_Bar')); 38 | $this->assertTrue($loader->isLocalName('Foo')); 39 | $loader->clearLocalNamespace(); 40 | $loader->registerLocalNamespace('Bar'); 41 | $this->assertFalse($loader->isLocalName('Foo_Bar')); 42 | $this->assertTrue($loader->isLocalName('Bar')); 43 | } 44 | 45 | public function tearDown() 46 | { 47 | parent::setUp(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/P062Test.php: -------------------------------------------------------------------------------- 1 | assertSame('Expects an absolute path for templates directory', $e->getMessage()); 33 | } 34 | $this->assertTrue($exception); 35 | 36 | $config = [ 37 | 'application' => [ 38 | 'directory' => __DIR__, 39 | ], 40 | ]; 41 | $app = new Application($config); 42 | 43 | $view = Dispatcher::getInstance()->initView([]); 44 | $this->assertNull($view->getScriptPath()); 45 | } 46 | 47 | public function tearDown() 48 | { 49 | parent::setUp(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/P084Test.php: -------------------------------------------------------------------------------- 1 | $method()); 30 | TestCase::assertSame(1, $request->isGet() + $request->isPost() + $request->isHead() 31 | + $request->isDelete() + $request->isPut() + $request->isOptions() 32 | + $request->isPatch()); 33 | } 34 | 35 | checkMethod('GET'); 36 | checkMethod('POST'); 37 | checkMethod('HEAD'); 38 | checkMethod('DELETE'); 39 | checkMethod('PUT'); 40 | checkMethod('OPTIONS'); 41 | checkMethod('PATCH'); 42 | } 43 | 44 | public function tearDown() 45 | { 46 | parent::setUp(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/P006Test.php: -------------------------------------------------------------------------------- 1 | assertTrue($route->route($request)); 31 | $this->assertNull($request->module); 32 | $this->assertSame('controller', $request->controller); 33 | $this->assertSame('action', $request->action); 34 | $this->assertSame('Cli', $request->method); 35 | $this->assertSame([ 36 | 'name' => 'laruence', 37 | 'age' => 28 38 | ], $request->getParams()); 39 | $this->assertSame('/prefix/', $request->getBaseUri()); 40 | $this->assertSame('/prefix/controller/action/name/laruence/age/28', $request->getRequestUri()); 41 | } 42 | 43 | public function tearDown() 44 | { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/P050Test.php: -------------------------------------------------------------------------------- 1 | [ 29 | 'directory' => YAF_TEST_APPLICATION_PATH, 30 | ], 31 | ]; 32 | 33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/050Test_1.inc')); 34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/050Test_2.inc')); 35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', 'view'); 36 | 37 | $app = new Application($config); 38 | $response = $app->bootstrap()->run(); 39 | $this->assertSame('view', (string) $response); 40 | } 41 | 42 | public function tearDown() 43 | { 44 | parent::setUp(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/P037Test.php: -------------------------------------------------------------------------------- 1 | import($dir . '/Dummy.php'); 37 | $loader->autoload('Dummy'); 38 | } 39 | 40 | public function tearDown() 41 | { 42 | parent::setUp(); 43 | @unlink(__DIR__ . '/common/tmp_build/Dummy.php'); 44 | 45 | YAF_G('yaf.lowcase_path', YAF_G('bak_lowcase_path')); 46 | YAF_G('yaf.use_spl_autoload', YAF_G('bak_use_spl_autoload')); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/P024Test.php: -------------------------------------------------------------------------------- 1 | assertSame('/foo', $loader->getLibraryPath()); 31 | $this->assertSame('/bar', $loader->getLibraryPath(true)); 32 | 33 | $config = [ 34 | 'application' => [ 35 | 'directory' => realpath(dirname(__FILE__)), 36 | ], 37 | ]; 38 | 39 | $app = new Application($config); 40 | $this->assertRegExp('/^[\w\/-]+library$/', $loader->getLibraryPath()); 41 | $this->assertSame('/php/global/dir', $loader->getLibraryPath(true)); 42 | } 43 | 44 | public function tearDown() 45 | { 46 | parent::tearDown(); 47 | 48 | YAF_G('yaf.library', YAF_G('bak_library')); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /psr0/view/Interface.php: -------------------------------------------------------------------------------- 1 | addRoute('subdir', new Regex('#/subdir/(.*)#', 30 | [ 31 | 'action' => 'version', 32 | ], 33 | [] 34 | )) 35 | ->addRoute('ap', new Regex('#^/ap/([^/]*)/*#i', 36 | [ 37 | 'action' => 'ap', 38 | ], 39 | [ 40 | 1 => 'version', 41 | ] 42 | ))->route($request); 43 | 44 | $this->assertSame('ap', $router->getCurrentRoute()); 45 | $this->assertSame('1.2', $request->getParam('version')); 46 | $this->assertSame('ap', $request->getActionName()); 47 | $this->assertNull($request->getControllerName()); 48 | $this->assertNull($request->getParam('name')); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /psr4/view/Interface.php: -------------------------------------------------------------------------------- 1 | "product", //route to product controller, 31 | ), 32 | array(), 33 | array(), 34 | '/:m/:c/:a' 35 | ); 36 | 37 | $router->addRoute("regex", $route); 38 | 39 | $this->assertSame('/module/controller/action?tkey1=tval1&tkey2=tval2', 40 | $router->getRoute('regex')->assemble([ 41 | ':m' => 'module', 42 | ':c' => 'controller', 43 | ':a' => 'action' 44 | ], 45 | [ 46 | 'tkey1' => 'tval1', 47 | 'tkey2' => 48 | 'tval2' 49 | ] 50 | ) 51 | ); 52 | } 53 | 54 | public function tearDown() 55 | { 56 | parent::setUp(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/P078Test.php: -------------------------------------------------------------------------------- 1 | addRoute('map', $route); 29 | 30 | $this->assertSame('/foo/bar?tkey1=tval1&tkey2=tval2', $router->getRoute('map')->assemble( 31 | array( 32 | ':c' => 'foo_bar' 33 | ), 34 | array( 35 | 'tkey1' => 'tval1', 36 | 'tkey2' => 'tval2' 37 | ) 38 | )); 39 | 40 | $route = new Map(true, '_'); 41 | $router->addRoute('map', $route); 42 | 43 | $this->assertSame('/foo/bar/_/tkey1/tval1/tkey2/tval2', $router->getRoute('map')->assemble( 44 | array( 45 | ':a' => 'foo_bar' 46 | ), 47 | array( 48 | 'tkey1' => 'tval1', 49 | 'tkey2' => 'tval2' 50 | ) 51 | )); 52 | } 53 | 54 | public function tearDown() 55 | { 56 | parent::setUp(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/P060Test.php: -------------------------------------------------------------------------------- 1 | [ 30 | 'directory' => YAF_TEST_APPLICATION_PATH, 31 | ], 32 | ]; 33 | 34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/060Test_1.inc')); 35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/060Test_2.inc')); 36 | file_put_contents(YAF_TEST_APPLICATION_PATH . "/views/index/index.phtml", ""); 37 | 38 | ob_start(); 39 | $app = new Application($config); 40 | $response = $app->bootstrap()->run(); 41 | $actual = ob_get_contents(); 42 | ob_end_clean(); 43 | 44 | $this->assertSame('Dummy', $actual); 45 | } 46 | 47 | public function tearDown() 48 | { 49 | parent::setUp(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/P025Test.php: -------------------------------------------------------------------------------- 1 | [ 30 | 'directory' => realpath(dirname(__FILE__)), 31 | 'library' => [ 32 | 'directory' => '/tmp', 33 | 'namespace' => 'Foo, Bar', 34 | ], 35 | ], 36 | ]; 37 | 38 | $app = new Application($config); 39 | Loader::getInstance()->registerLocalNamespace('Dummy'); 40 | $loader = Loader::getInstance(); 41 | $this->assertSame('/tmp', $loader->getLibraryPath()); 42 | $this->assertSame('/php/global/dir', $loader->getLibraryPath(true)); 43 | $this->assertTrue(Loader::getInstance()->isLocalName('Bar_Name')); 44 | } 45 | 46 | public function tearDown() 47 | { 48 | parent::tearDown(); 49 | 50 | YAF_G('yaf.library', YAF_G('bak_library')); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/P069Test.php: -------------------------------------------------------------------------------- 1 | [ 29 | 'directory' => YAF_TEST_APPLICATION_PATH, 30 | ], 31 | ]; 32 | 33 | file_put_contents(YAF_TEST_APPLICATION_PATH . "/controllers/Index.php", << tail" . PHP_EOL); 44 | 45 | ob_start(); 46 | $app = new Application($config); 47 | $app->run(); 48 | $acutal = ob_get_contents(); 49 | ob_end_clean(); 50 | 51 | $this->assertTrue(stripos($acutal, 'head') !== false && stripos($acutal, 'tail') !== false); 52 | } 53 | 54 | public function tearDown() 55 | { 56 | parent::setUp(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/P061Test.php: -------------------------------------------------------------------------------- 1 | [ 29 | 'directory' => YAF_TEST_APPLICATION_PATH, 30 | ], 31 | ]; 32 | 33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/061Test_1.inc')); 34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Dummy.php', file_get_contents(__DIR__ . '/common/061Test_2.inc')); 35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', ''); 36 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/dummy.phtml', 'Dummy'); 37 | 38 | ob_start(); 39 | $app = new Application($config); 40 | $response = $app->run(); 41 | $actual = ob_get_contents(); 42 | ob_end_clean(); 43 | 44 | $this->assertSame('Dummy', $actual); 45 | } 46 | 47 | public function tearDown() 48 | { 49 | parent::setUp(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/P065Test.php: -------------------------------------------------------------------------------- 1 | addConfig( 30 | [ 31 | [ 32 | 'type' => 'regex', 33 | 'match' => "#^/ap/([^/]*)/*#i", 34 | 'route' => [ 35 | [ 36 | 'action' => 'ap', 37 | ], 38 | ], 39 | ] 40 | ] 41 | )->route($request); 42 | 43 | $this->assertSame(0, $router->getCurrentRoute()); 44 | $this->assertNull($request->getActionName()); 45 | 46 | $router->addRoute('regex', new Regex("#^/ap/([^/]*)/*#i", ['action' => 'ap']))->route($request); 47 | 48 | $this->assertSame('regex', $router->getCurrentRoute()); 49 | $this->assertSame('ap', $request->getActionName()); 50 | } 51 | 52 | public function tearDown() 53 | { 54 | parent::setUp(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/P039Test.php: -------------------------------------------------------------------------------- 1 | markTestSkipped('syntax error test'); 18 | 19 | require_once __DIR__ . '/common/build.inc'; 20 | startup(); 21 | } 22 | 23 | /** 24 | * @throws Exception 25 | */ 26 | public function test() 27 | { 28 | $view = new Simple(DIR_ROOT); 29 | $view->assign('name', 'laruence'); 30 | $tpl = YAF_TEST_APPLICATION_PATH . '/tpls/foo.phtml'; 31 | $tpl2 = YAF_TEST_APPLICATION_PATH . '/tpls/foo2.phtml'; 32 | 33 | file_put_contents($tpl, <<render(\$tpl); 36 | ?> 37 | HTML 38 | ); 39 | 40 | file_put_contents($tpl2, << 45 | HTML 46 | ); 47 | 48 | $exception = false; 49 | try { 50 | echo $view->render($tpl, ['tpl' => $tpl2]); 51 | } catch (Error $e) { 52 | $exception = true; 53 | $this->assertSame("syntax error, unexpected '}'", $e->getMessage()); 54 | } 55 | 56 | $this->assertTrue($exception); 57 | } 58 | 59 | public function tearDown() 60 | { 61 | parent::setUp(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tests/P059Test.php: -------------------------------------------------------------------------------- 1 | [ 28 | 'directory' => YAF_TEST_APPLICATION_PATH, 29 | ], 30 | ]; 31 | 32 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/059Test_1.inc')); 33 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/059Test_2.inc')); 34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', "display('index/sub.phtml', array('content' => 'dummy'));?>"); 35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/sub.phtml', "eval('foobar'); ?>"); 36 | 37 | $app = new Application($config); 38 | ob_start(); 39 | $response = $app->bootstrap()->run(); 40 | $actual = ob_get_contents(); 41 | ob_end_clean(); 42 | 43 | $this->assertTrue(stripos($actual, 'dummyfoobar') !== false); 44 | } 45 | 46 | public function tearDown() 47 | { 48 | parent::setUp(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/P073Test.php: -------------------------------------------------------------------------------- 1 | 'product', 28 | ], []); 29 | $router->addRoute('rewrite', $route); 30 | 31 | $this->assertSame('/product/foo/bar/tmpkey1/tmpval1/?tkey1=tval1&tkey2=tval2', $router->getRoute('rewrite')->assemble( 32 | [ 33 | ':name' => 'foo', 34 | ':id' => 'bar', 35 | ':tmpkey1' => 'tmpval1' 36 | ], 37 | [ 38 | 'tkey1' => 'tval1', 39 | 'tkey2' => 'tval2' 40 | ] 41 | )); 42 | 43 | $this->assertSame('/product/foo/1/tmpkey1/tmpval1/?tkey1=tval1&tkey2=22222', $router->getRoute('rewrite')->assemble( 44 | [ 45 | ':name' => 'foo', 46 | ':id' => 1, 47 | ':tmpkey1' => 'tmpval1' 48 | ], 49 | [ 50 | 'tkey1' => 'tval1', 51 | 'tkey2' => 22222 52 | ] 53 | )); 54 | } 55 | 56 | public function tearDown() 57 | { 58 | parent::setUp(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/P077Test.php: -------------------------------------------------------------------------------- 1 | addRoute('static', $route); 29 | 30 | $this->assertSame('/yafmodule/yafcontroller/yafaction?tkey1=tval1&tkey2=tval2', $router->getRoute('static')->assemble( 31 | array( 32 | ':a' => 'yafaction', 33 | 'tkey' => 'tval', 34 | ':c' => 'yafcontroller', 35 | ':m' => 'yafmodule' 36 | ), 37 | array( 38 | 'tkey1' => 'tval1', 39 | 'tkey2' => 'tval2' 40 | ) 41 | ) 42 | ); 43 | 44 | $this->assertSame('/yafmodule/yafcontroller/yafaction', $router->getRoute('static')->assemble( 45 | array( 46 | ':a' => 'yafaction', 47 | 'tkey' => 'tval', 48 | ':c' => 'yafcontroller', 49 | ':m' => 'yafmodule' 50 | ), 51 | array( 52 | 1 => 2, 53 | array(), 54 | ) 55 | )); 56 | } 57 | 58 | public function tearDown() 59 | { 60 | parent::setUp(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/P067Test.php: -------------------------------------------------------------------------------- 1 | [ 30 | 'directory' => YAF_TEST_APPLICATION_PATH, 31 | ], 32 | ]; 33 | 34 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/067Test_1.inc')); 35 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/actions/sub.php', file_get_contents(__DIR__ . '/common/067Test_2.inc')); 36 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml', 'indexAction' . PHP_EOL); 37 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/sub.phtml', 'subAction' . PHP_EOL); 38 | 39 | $app = new Application($config); 40 | 41 | $request = new Simple(); 42 | $app->getDispatcher()->dispatch($request); 43 | 44 | $new_request = new Simple(); 45 | $new_request->setActionName('sub'); 46 | $app->getDispatcher()->dispatch($new_request); 47 | 48 | $this->assertSame('ok', 'ok'); 49 | } 50 | 51 | public function tearDown() 52 | { 53 | parent::setUp(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/P005Test.php: -------------------------------------------------------------------------------- 1 | appendBody($body); 31 | $response->prependBody($string); 32 | $response->appendBody('kfjdaksljfklajdsfkljasdkljfkjasdf'); 33 | 34 | $body = $response->getBody(); 35 | $this->assertSame('content', Response_Abstract::DEFAULT_BODY); 36 | $this->assertSame([ 37 | 'content' => 'laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf' 38 | ], $response->getBody(null)); 39 | $this->assertSame( 40 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf', 41 | $response->getBody(Http::DEFAULT_BODY) 42 | ); 43 | $this->assertEquals('laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf', $response); 44 | 45 | ob_start(); 46 | $response->response(); 47 | $response = ob_get_contents(); 48 | ob_end_clean(); 49 | $this->assertEquals('laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf', $response); 50 | } 51 | 52 | public function tearDown() 53 | { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/P027Test.php: -------------------------------------------------------------------------------- 1 | [ 33 | 'directory' => realpath(dirname(__FILE__)), 34 | 'dispatcher' => [ 35 | 'catchException' => 0, 36 | 'throwException' => 0, 37 | ], 38 | ], 39 | ]; 40 | 41 | $app = new Application($config); 42 | $this->assertSame('product', $app->environ()); 43 | $this->assertSame(2, count($app->getConfig()->application)); 44 | 45 | @$app->execute(123); 46 | $this->assertSame('Yaf_Application::execute must be a valid callback', error_get_last()['message']); 47 | } 48 | 49 | public function tearDown() 50 | { 51 | parent::tearDown(); 52 | 53 | YAF_G('yaf.use_spl_autoload', YAF_G('bak_use_spl_autoload')); 54 | YAF_G('yaf.library', YAF_G('bak_library')); 55 | YAF_G('yaf.environ', YAF_G('bak_environ')); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/P042Test.php: -------------------------------------------------------------------------------- 1 | [ 42 | 'directory' => realpath(dirname(__FILE__)), 43 | 'dispatcher' => [ 44 | 'catchException' => 0, 45 | 'throwException' => 1, 46 | ], 47 | 'modules' => 'module', 48 | ], 49 | ]; 50 | 51 | 52 | $app = new Application($config); 53 | $request = new Http('/module/controller/index'); 54 | 55 | $exception = false; 56 | try { 57 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 58 | } catch (\Exception $e) { 59 | $exception = true; 60 | $this->assertSame('exception', $e->getMessage()); 61 | } 62 | $this->assertTrue($exception); 63 | } 64 | 65 | public function tearDown() 66 | { 67 | parent::setUp(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/P016Test.php: -------------------------------------------------------------------------------- 1 | age = $age; 32 | unset($age); 33 | 34 | unset($session); 35 | $session2 = @Session::getInstance(); 36 | $session2["company"] = "Baidu"; 37 | $this->assertTrue(isset($session2->age)); 38 | $this->assertTrue($session2->has("name")); 39 | $this->assertSame(3, count($session2)); 40 | 41 | ob_start(); 42 | foreach ($session2 as $key => $value) { 43 | echo $key , "=>", $value, "\n"; 44 | } 45 | $actual = ob_get_contents(); 46 | ob_end_clean(); 47 | 48 | $expected = <<Laruence 50 | age=>28 51 | company=>Baidu 52 | 53 | OUTPUT; 54 | 55 | $this->assertSame($expected, $actual); 56 | unset($session2); 57 | 58 | $session3 = @Session::getInstance(); 59 | $session3->del("name"); 60 | unset($session3["company"]); 61 | unset($session3->age); 62 | 63 | $this->assertSame(0, count($session3)); 64 | } 65 | 66 | public function tearDown() 67 | { 68 | $_SESSION = []; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/P053Test.php: -------------------------------------------------------------------------------- 1 | _tpl_vars[$name] = $value; 12 | } 13 | } 14 | 15 | /** 16 | * Check for Custom view engine 17 | * 18 | * @run ./vendor/bin/phpunit --bootstrap ./tests/bootstrap.php ./tests/P053Test.php 19 | */ 20 | class P053Test extends Base 21 | { 22 | public function setUp() 23 | { 24 | parent::setUp(); 25 | 26 | require __DIR__ . '/common/build.inc'; 27 | startup(); 28 | } 29 | 30 | /** 31 | * @throws Exception 32 | * @throws ReflectionException 33 | * @throws TypeError 34 | */ 35 | public function test() 36 | { 37 | $config = [ 38 | 'application' => [ 39 | 'directory' => YAF_TEST_APPLICATION_PATH, 40 | ], 41 | ]; 42 | 43 | $tpl_dir = YAF_TEST_APPLICATION_PATH . '/views'; 44 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/053Test_1.inc')); 45 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/053Test_2.inc')); 46 | file_put_contents($tpl_dir . '/index/index.phtml', file_get_contents(__DIR__ . '/common/053Test_3.inc')); 47 | 48 | $app = new Application($config); 49 | ob_start(); 50 | $response = $app->bootstrap()->run(); 51 | $actual = ob_get_contents(); 52 | ob_end_clean(); 53 | 54 | $this->assertSame('custom view', $actual); 55 | } 56 | 57 | public function tearDown() 58 | { 59 | parent::setUp(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/P022Test.php: -------------------------------------------------------------------------------- 1 | [ 28 | 'directory' => realpath(__DIR__), 29 | 'dispatcher' => [ 30 | 'catchException' => 0, 31 | 'throwException' => 0, 32 | ], 33 | ], 34 | ]; 35 | 36 | $app = new Application($config); 37 | $this->assertSame(__DIR__, $app->getAppDirectory()); 38 | 39 | $dir = $app->getAppDirectory() . '/tmp'; 40 | mkdir($dir); 41 | $app->setAppDirectory($dir); 42 | $this->assertSame(__DIR__ . '/tmp', $app->getAppDirectory()); 43 | 44 | $exception = false; 45 | try { 46 | $app->run(); 47 | } catch (Exception $e) { 48 | $exception = true; 49 | $this->assertTrue( 50 | strncmp( 51 | 'Failed opening controller script %s: %s', 52 | Application::app()->getLastErrorMsg(), 53 | strlen('Failed opening controller script ') 54 | ) === 0 55 | ); 56 | } 57 | 58 | $this->assertTrue($exception); 59 | } 60 | 61 | public function tearDown() 62 | { 63 | parent::tearDown(); 64 | if (is_dir(__DIR__ . '/tmp')) { 65 | rmdir(__DIR__ . '/tmp'); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/P020Test.php: -------------------------------------------------------------------------------- 1 | [ 26 | 'directory' => realpath(dirname(__FILE__)), 27 | 'dispatcher' => [ 28 | 'catchException' => 0, 29 | 'throwException' => 0, 30 | ], 31 | ], 32 | ]; 33 | 34 | $GLOBALS['P020Test'] = 0; 35 | function error_handler(...$errInfo) { 36 | echo PHP_EOL . 'P020Test begin' . PHP_EOL; 37 | 38 | ++$GLOBALS['P020Test']; 39 | TestCase::assertSame(516, Application::app()->getLastErrorNo()); 40 | TestCase::assertTrue( 41 | strncmp( 42 | 'Failed opening controller script %s: %s', 43 | Application::app()->getLastErrorMsg(), 44 | strlen('Failed opening controller script ') 45 | ) === 0 46 | ); 47 | Application::app()->clearLastError(); 48 | TestCase::assertSame(0, Application::app()->getLastErrorNo()); 49 | TestCase::assertSame("", Application::app()->getLastErrorMsg()); 50 | TestCase::assertSame(1, $GLOBALS['P020Test']); 51 | }; 52 | 53 | $app = new Application($config); 54 | // $app->getDispatcher()->setErrorHandler('error_handler', E_RECOVERABLE_ERROR); 55 | $app->getDispatcher()->setErrorHandler('error_handler', E_ALL); 56 | $app->run(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/P076Test.php: -------------------------------------------------------------------------------- 1 | addRoute('supervar', $route); 29 | 30 | $this->assertSame('?r=/yafmodule/yafcontroller/yafaction&tkey1=tval1&tkey2=tval2', $router->getRoute('supervar')->assemble( 31 | array( 32 | ':a' => 'yafaction', 33 | 'tkey' => 'tval', 34 | ':c' => 'yafcontroller', 35 | ':m' => 'yafmodule' 36 | ), 37 | array( 38 | 'tkey1' => 'tval1', 39 | 'tkey2' => 'tval2' 40 | ) 41 | )); 42 | 43 | $expect = false; 44 | try { 45 | $router->getRoute('supervar')->assemble( 46 | array( 47 | ':a' => 'yafaction', 48 | 'tkey' => 'tval', 49 | ':m' => 'yafmodule' 50 | ), 51 | array( 52 | 'tkey1' => 'tval1', 53 | 'tkey2' => 'tval2', 54 | 1 => array(), 55 | ) 56 | ); 57 | } catch (Exception $e) { 58 | $expect = true; 59 | $this->assertSame("You need to specify the controller by ':c'", $e->getMessage()); 60 | } 61 | $this->assertTrue($expect); 62 | } 63 | 64 | public function tearDown() 65 | { 66 | parent::setUp(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/P045Test.php: -------------------------------------------------------------------------------- 1 | setErrorHandler(function($errorCode, $errorMessage, $file, $line) { 18 | throw new ErrorException($errorMessage, 0, $errorCode, $file, $line); 19 | }); 20 | } 21 | } 22 | 23 | class IndexController extends Controller_Abstract 24 | { 25 | public function indexAction() 26 | { 27 | echo $undefined_var; 28 | return false; 29 | } 30 | } 31 | 32 | /** 33 | * Check for segfault while use closure as error handler 34 | * 35 | * @run ./vendor/bin/phpunit --bootstrap ./tests/bootstrap.php ./tests/P045Test.php 36 | */ 37 | class P045Test extends Base 38 | { 39 | public function setUp() 40 | { 41 | parent::setUp(); 42 | } 43 | 44 | /** 45 | * @throws \Exception 46 | */ 47 | public function test() 48 | { 49 | $config = [ 50 | 'application' => [ 51 | 'directory' => __DIR__, 52 | 'dispatcher' => [ 53 | 'catchException' => 0, 54 | 'throwException' => 0, 55 | ], 56 | ], 57 | ]; 58 | 59 | $exception = false; 60 | $app = new Application($config); 61 | try { 62 | $app->bootstrap()->run(); 63 | } catch (\Exception $e) { 64 | $exception = true; 65 | $this->assertSame('Undefined variable: undefined_var', $e->getMessage()); 66 | } 67 | $this->assertTrue($exception); 68 | } 69 | 70 | public function tearDown() 71 | { 72 | parent::setUp(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/P049Test.php: -------------------------------------------------------------------------------- 1 | [ 32 | 'directory' => YAF_TEST_APPLICATION_PATH, 33 | 'dispatcher' => [ 34 | 'catchException' => true, 35 | ], 36 | 'library' => [ 37 | ], 38 | ], 39 | ]; 40 | 41 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Error.php', file_get_contents(__DIR__ . '/common/049Test_1.inc')); 42 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/049Test_2.inc')); 43 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/plugins/Test.php', file_get_contents(__DIR__ . '/common/049Test_3.inc')); 44 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/049Test_4.inc')); 45 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml',file_get_contents(__DIR__ . '/common/049Test_5.inc')); 46 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/error/error.phtml',file_get_contents(__DIR__ . '/common/049Test_6.inc')); 47 | 48 | ob_start(); 49 | $app = new Application($config); 50 | $app->bootstrap()->run(); 51 | ob_end_flush(); 52 | 53 | // exit; 54 | } 55 | 56 | public function tearDown() 57 | { 58 | parent::setUp(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/P003Test.php: -------------------------------------------------------------------------------- 1 | registerLocalNamespace('Baidu'); 32 | $loader->registerLocalNamespace('Sina'); 33 | $loader->registerLocalNamespace(['Wb', 'Inf', null, [], '123']); 34 | 35 | $this->assertEquals('Baidu;Sina;Wb;Inf;123', $loader->getLocalNamespace()); 36 | 37 | //--------------------------------------- 38 | 39 | $catch = false; 40 | try { 41 | $loader->autoload('Baidu_Name'); 42 | } catch (\Exception $e) { 43 | $this->assertSame(E_WARNING, $e->getCode()); 44 | $this->assertTrue((bool) preg_match('/^Failed opening script [\s\S]+/', $e->getMessage())); 45 | $catch = true; 46 | } 47 | $this->assertTrue($catch); 48 | 49 | //--------------------------------------- 50 | 51 | $catch = false; 52 | try { 53 | $loader->autoload('Global_Name'); 54 | } catch (\Exception $e) { 55 | $this->assertSame(E_WARNING, $e->getCode()); 56 | $this->assertTrue((bool) preg_match('/^Failed opening script [\s\S]+/', $e->getMessage())); 57 | $catch = true; 58 | } 59 | $this->assertTrue($catch); 60 | } 61 | 62 | public function tearDown() 63 | { 64 | YAF_G('yaf.use_spl_autoload', null); 65 | YAF_G('yaf.lowcase_path', null); 66 | YAF_G('yaf.use_namespace', null); 67 | YAF_G('ap.lowcase_path', null); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/P063Test.php: -------------------------------------------------------------------------------- 1 | 'm', 31 | 'controller' => ':1', 32 | 'action' => ':a', 33 | ] 34 | ); 35 | $route_2 = new Rewrite('/yaf/:action/*', [ 36 | 'action' => ':action', 37 | 'controller' => 'index', 38 | ] 39 | ); 40 | 41 | $router 42 | ->addRoute('subdir', $route_1) 43 | ->addRoute('yaf', $route_2) 44 | ->route($request); 45 | 46 | $this->assertSame('subdir', $router->getCurrentRoute()); 47 | $this->assertSame([ 48 | 'con' => 'ctl', 49 | 'a' => 'act', 50 | 'name' => 'value' 51 | ], $request->getParams()); 52 | $this->assertSame('act', $request->getActionName()); 53 | $this->assertNull($request->getControllerName()); 54 | $this->assertSame('m', $request->getModuleName()); 55 | 56 | $request = new Http('/yaf/act/name/value'); 57 | $router->route($request); 58 | 59 | $this->assertSame('yaf', $router->getCurrentRoute()); 60 | $this->assertSame([ 61 | 'action' => 'act', 62 | 'name' => 'value', 63 | ], $request->getParams()); 64 | $this->assertSame('act', $request->getActionName()); 65 | $this->assertSame('index', $request->getControllerName()); 66 | $this->assertNull($request->getModuleName()); 67 | } 68 | 69 | public function tearDown() 70 | { 71 | parent::setUp(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/P023Test.php: -------------------------------------------------------------------------------- 1 | registerLocalNamespace(['Foo']); 32 | 33 | @$loader->autoload('Foo_Bar'); 34 | $this->assertSame('Failed opening script /foo/Foo/Bar.php', error_get_last()['message']); 35 | @$loader->autoload('Bar_Foo'); 36 | $this->assertSame('Failed opening script /bar/Bar/Foo.php', error_get_last()['message']); 37 | 38 | $loader->setLibraryPath('/foobar', false); 39 | @$loader->autoload('Foo_Bar'); 40 | $this->assertSame('Failed opening script /foobar/Foo/Bar.php', error_get_last()['message']); 41 | @$loader->autoload('Bar_Foo'); 42 | $this->assertSame('Failed opening script /bar/Bar/Foo.php', error_get_last()['message']); 43 | 44 | $loader->setLibraryPath('/foobar', true); 45 | @$loader->autoload('Foo_Bar'); 46 | $this->assertSame('Failed opening script /foobar/Foo/Bar.php', error_get_last()['message']); 47 | @$loader->autoload('Bar_Foo'); 48 | $this->assertSame('Failed opening script /foobar/Bar/Foo.php', error_get_last()['message']); 49 | 50 | @$loader->autoload('Bar_Model'); 51 | $this->assertSame("Couldn't load a MVC class unless an Yaf\Application is initialized", error_get_last()['message']); 52 | } 53 | 54 | public function tearDown() 55 | { 56 | parent::tearDown(); 57 | 58 | YAF_G('yaf.use_spl_autoload', YAF_G('bak_use_spl_autoload')); 59 | YAF_G('yaf.lowcase_path', YAF_G('bak_lowcase_path')); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/P064Test.php: -------------------------------------------------------------------------------- 1 | .*?)/(.*?)/.*#", 30 | [ 31 | 'module' => 'm', 32 | 'controller' => ':c', 33 | 'action' => ':a', 34 | ], 35 | [ 36 | 2 => 'a', 37 | ] 38 | ); 39 | $route_2 = new Regex("#yaf/(.*?)/.*#", 40 | [ 41 | 'action' => ':action', 42 | 'controller' => 'index', 43 | ], 44 | [ 45 | 1 => 'action', 46 | ] 47 | ); 48 | 49 | $router 50 | ->addRoute('subdir', $route_1) 51 | ->addRoute('yaf', $route_2) 52 | ->route($request); 53 | 54 | $this->assertSame('subdir', $router->getCurrentRoute()); 55 | $this->assertSame([ 56 | 'c' => 'ctl', 57 | 'a' => 'act', 58 | ], $request->getParams()); 59 | $this->assertSame('act', $request->getActionName()); 60 | $this->assertSame('ctl', $request->getControllerName()); 61 | $this->assertSame('m', $request->getModuleName()); 62 | 63 | $request = new Http('/yaf/act/name/value'); 64 | $router->route($request); 65 | 66 | $this->assertSame('yaf', $router->getCurrentRoute()); 67 | $this->assertSame([ 68 | 'action' => 'act' 69 | ],$request->getParams()); 70 | $this->assertSame('act', $request->getActionName()); 71 | $this->assertSame('index', $request->getControllerName()); 72 | $this->assertNull($request->getModuleName()); 73 | } 74 | 75 | public function tearDown() 76 | { 77 | parent::setUp(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/P052Test.php: -------------------------------------------------------------------------------- 1 | assertSame('Yaf\Request\Http::__construct expects at most 2 parameters, 3 given', $e->getMessage()); 27 | } 28 | 29 | $this->assertTrue($exception); 30 | } 31 | 32 | /** 33 | * @throws TypeError 34 | */ 35 | public function testRequestSuccess() 36 | { 37 | $request = new Http('xxxxxxxxxxxxxxxxxxxxxxxxxxx'); 38 | $this->assertNull($request->get('xxx')); 39 | $this->assertNull($request->getQuery('xxx')); 40 | $this->assertNull($request->getServer('xxx')); 41 | $this->assertNull($request->getPost('xxx')); 42 | $this->assertNull($request->getCookie('xxx')); 43 | $this->assertNull($request->getEnv('xxx')); 44 | 45 | // ------default value-------; 46 | 47 | $this->assertSame('123', $request->get('xxx', '123')); 48 | $std = new stdClass(); 49 | $this->assertSame($std, $request->getQuery('xxx', $std)); 50 | $this->assertSame([], $request->getServer('xxx', [])); 51 | $this->assertNull($request->getPost('xxx', null)); 52 | $this->assertFalse($request->getCookie('xxx', false)); 53 | $this->assertSame('2.13232', $request->getEnv('xxx', '2.13232')); 54 | 55 | // ------params------- 56 | 57 | $this->assertNull($request->setParam('xxxx')); 58 | $this->assertNull($request->getParam('xxxx')); 59 | $this->assertSame([], $request->getParams()); 60 | 61 | // ------others------- 62 | $this->assertFalse($request->isXmlHttpRequest()); 63 | $this->assertTrue($request->isCli()); 64 | $this->assertFalse($request->isPost()); 65 | } 66 | 67 | public function tearDown() 68 | { 69 | parent::setUp(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/P048Test.php: -------------------------------------------------------------------------------- 1 | [ 32 | 'directory' => YAF_TEST_APPLICATION_PATH, 33 | 'dispatcher' => [ 34 | 'catchException' => true, 35 | ], 36 | 'library' => [ 37 | ], 38 | ], 39 | ]; 40 | 41 | ob_start(); 42 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Error.php', file_get_contents(__DIR__ . '/common/048Test_1.inc')); 43 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/Bootstrap.php', file_get_contents(__DIR__ . '/common/048Test_2.inc')); 44 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/plugins/Test.php', file_get_contents(__DIR__ . '/common/048Test_3.inc')); 45 | $value = null; 46 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/controllers/Index.php', file_get_contents(__DIR__ . '/common/048Test_4.inc')); 47 | file_put_contents(YAF_TEST_APPLICATION_PATH . '/views/index/index.phtml',file_get_contents(__DIR__ . '/common/048Test_5.inc')); 48 | 49 | $app = new Application($config); 50 | $app->bootstrap()->run(); 51 | $content = ob_get_contents(); 52 | ob_end_clean(); 53 | 54 | $expect = <<assertSame($expect, $content); 69 | } 70 | 71 | public function tearDown() 72 | { 73 | parent::setUp(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/P0bug62702Test.php: -------------------------------------------------------------------------------- 1 | route($request); 33 | $this->assertNull($request->getControllerName()); 34 | 35 | $request = new Http('/Sample/ABC', '/sample'); 36 | $router->route($request); 37 | $this->assertSame('ABC', $request->getControllerName()); 38 | 39 | // 2. map router 40 | $router = new Map(true); 41 | 42 | $request = new Http('/sample/A/B/C', '/sample'); 43 | $router->route($request); 44 | $this->assertSame('A_B_C', $request->getControllerName()); 45 | 46 | $request = new Http('/sample', '/sAmplE'); 47 | $router->route($request); 48 | $this->assertNull($request->getControllerName()); 49 | 50 | // 3. regex router 51 | $router = new Regex('#^/test#', ['controller' => 'info'], []); 52 | 53 | $request = new Http('/test/', '/Test'); 54 | $router->route($request); 55 | $this->assertNull($request->getControllerName()); 56 | 57 | $request = new Http('/sample/test', '/sAmplE'); 58 | $router->route($request); 59 | $this->assertSame('info', $request->getControllerName()); 60 | 61 | // 4. rewrite router 62 | $router = new Rewrite('/test', ['controller' => 'info'], []); 63 | 64 | $request = new Http('/test/', '/Test'); 65 | $router->route($request); 66 | $this->assertNull($request->getControllerName()); 67 | 68 | $request = new Http('/sample/test', '/sAmplE'); 69 | $router->route($request); 70 | $this->assertSame('info', $request->getControllerName()); 71 | } 72 | 73 | public function tearDown() 74 | { 75 | parent::setUp(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/P072Test.php: -------------------------------------------------------------------------------- 1 | assertTrue($response->setHeader('MyName1', 'Header1')); 28 | $this->assertTrue($response->setHeader('MyName2', 'Header2')); 29 | $this->assertTrue($response->setHeader('MyName2', 'Header22')); 30 | $this->assertTrue($response->setHeader('MyName1', 'Header11', false)); 31 | $this->assertSame([ 32 | 'MyName1' => 'Header1, Header11', 33 | 'MyName2' => 'Header22' 34 | ], \YP\internalPropertyGet($response, '_header')); 35 | 36 | $this->assertTrue($response->setHeader('MyName1', 'Header1')); 37 | $this->assertTrue($response->setHeader('MyName3', 'Header31', false, 301)); 38 | $this->assertTrue($response->setHeader('MyName3', 'Header32', true, 302)); 39 | $this->assertTrue($response->setHeader('MyName1', 'Header2', false, 302)); 40 | 41 | $this->assertSame([ 42 | 'MyName1' => 'Header1, Header2', 43 | 'MyName2' => 'Header22', 44 | 'MyName3' => 'Header32' 45 | ], $response->getHeader()); 46 | $this->assertNull($response->getHeader('MyName')); 47 | $this->assertSame('Header1, Header2', $response->getHeader('MyName1')); 48 | $response->clearHeaders(); 49 | $this->assertSame([], \YP\internalPropertyGet($response, '_header')); 50 | 51 | $headers = [ 52 | 'MyName1' => 'Header1x', 53 | 'MyName2' => 'Header2x', 54 | 'MyName3' => 12345 55 | ]; 56 | $this->assertTrue($response->setAllHeaders($headers)); 57 | $this->assertSame([ 58 | 'MyName1' => 'Header1x', 59 | 'MyName2' => 'Header2x', 60 | 'MyName3' => '12345' 61 | ], $response->getHeader()); 62 | } 63 | 64 | public function tearDown() 65 | { 66 | parent::setUp(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/P018Test.php: -------------------------------------------------------------------------------- 1 | setAccessible(true); 30 | $this->assertSame($base, $configReflection->getValue($config)); 31 | } 32 | 33 | public function simpleData() 34 | { 35 | $baseData = [ 36 | 'application' => [ 37 | 'directory' => 'APPLICATION_PATH/applcation' 38 | ], 39 | 'name' => 'base', 40 | 'array' => [ 41 | 1 => 1, 42 | 'name' => 'name' 43 | ], 44 | '5' => 6, 45 | 'routes' => [ 46 | 'regex' => [ 47 | 'type' => 'regex', 48 | 'match' => '^/ap/(.*)', 49 | 'route' => [ 50 | 'controller' => 'Index', 51 | 'action' => 'action' 52 | ], 53 | 'map' => ['name', 'name', 'value'] 54 | ], 55 | 'simple' => [ 56 | 'type' => 'simple', 57 | 'controller' => 'c', 58 | 'module' => 'm', 59 | 'action' => 'a', 60 | ], 61 | 'supervar' => [ 62 | 'type' => 'supervar', 63 | 'varname' => 'c' 64 | ], 65 | 'rewrite' => [ 66 | 'type' => 'rewrite', 67 | 'match' => '/yaf/:name/:value', 68 | 'route' => [ 69 | 'controller' => 'Index', 70 | 'action' => 'action' 71 | ] 72 | ] 73 | ], 74 | 75 | ]; 76 | 77 | return [ 78 | [ 79 | $baseData, 80 | ] 81 | ]; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /psr4/Exception.php: -------------------------------------------------------------------------------- 1 | render($file); 44 | } 45 | 46 | ob_start(); 47 | file_put_contents(__DIR__ . '/common/tmp_build/outer.phtml', "1 3\n"); 48 | file_put_contents(__DIR__ . '/common/tmp_build/inner.phtml', "2"); 49 | print (view('outer.phtml')); 50 | $actual = ob_get_contents(); 51 | ob_end_clean(); 52 | $this->assertSame("1 2 3\n", $actual); 53 | 54 | ob_start(); 55 | file_put_contents(__DIR__ . '/common/tmp_build/outer.phtml', "1 display('inner.phtml');?> 3\n"); 56 | print (view('outer.phtml')); 57 | $actual = ob_get_contents(); 58 | ob_end_clean(); 59 | $this->assertSame("1 2 3\n", $actual); 60 | 61 | ob_start(); 62 | file_put_contents(__DIR__ . '/common/tmp_build/outer.phtml', "1 eval('2');?> 3\n"); 63 | print (view('outer.phtml')); 64 | $actual = ob_get_contents(); 65 | ob_end_clean(); 66 | $this->assertSame("1 2 3\n", $actual); 67 | 68 | $exception = false; 69 | try { 70 | file_put_contents(__DIR__ . '/common/tmp_build/outer.phtml', "1 display('inner.phtml');?> 3\n"); 71 | file_put_contents(__DIR__ . '/common/tmp_build/inner.phtml', ""); 72 | print (view('outer.phtml')); 73 | } catch (\Error $e) { 74 | $this->assertSame('Call to undefined function undefined_function()', $e->getMessage()); 75 | $exception = true; 76 | } 77 | $this->assertTrue($exception); 78 | } 79 | 80 | public function tearDown() 81 | { 82 | parent::setUp(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /psr0/Config.php: -------------------------------------------------------------------------------- 1 | 3 | YAF-PHP 4 |

5 | 6 |

7 | 8 | Test Case 9 | 10 | 11 | Yaf version 12 | 13 | 14 | version 15 | 16 | 17 | LICENSE 18 | 19 |

20 |
21 | 22 | # 目录 23 | 24 | + [1 关于Yaf-PHP](#1-关于yaf-php) 25 | + [1.1 简介](#11-简介) 26 | + [1.2 依赖](#12-依赖) 27 | + [1.3 安装](#13-安装) 28 | + [1.4 快速使用](#14-快速使用) 29 | - [1.4.1 PhpStorm引入](#141-在phpstorm引入) 30 | - [1.4.2 NetBeans引入](#142-在netbeans引入) 31 | + [1.5 最终效果图](#15-最终效果图) 32 | + [2 相关链接](#2-相关链接) 33 | + [3 待解决问题](#3待解决问题) 34 | 35 | # 1. 关于Yaf-PHP 36 | 37 | ## 1.1 简介 38 | 39 | ```Yaf-PHP```采用原生PHP对Yaf源码进行了逻辑重写,最大程度还原其相关实现逻辑. 40 | 41 | 由于采用了原生PHP重写,可达到抹平阅读能力,降低阅读成本的目的.在平常开发时,也可以作为IDE Helper进行引入,加快开发效率. 42 | 43 | ## 1.2 依赖 44 | 45 | | 依赖项 | 版本 | 说明 | 46 | |--------|--------|--------| 47 | | PHP | 7.0+ | IDE运行的PHP环境,并非服务运行环境 | 48 | 49 | ## 1.3 安装 50 | 51 | 52 | ```bash 53 | > git clone https://github.com/yinggaozhen/yaf-php.git 54 | ``` 55 | 56 | ## 1.4 快速使用 57 | 58 | ### 1.4.1 在PhpStorm引入 59 | 60 | 两种实现方法 61 | 62 | ~~~ 63 | 左侧导航栏 `External Libraries` -> `Configure PHP Include Path` -> 添加`Yaf-PHP`文件路径 -> `apply` 64 | ~~~ 65 | 66 | ~~~ 67 | 菜单 `File` -> `Setting` -> `Languages & Frameworks` -> `PHP` -> 添加`Yaf-PHP`文件路径 -> `apply` 68 | ~~~ 69 | 70 | ### 1.4.2 在NetBeans引入 71 | 72 | ~~~ 73 | 右击你的项目 -> `Properties` -> `PHP Include Path` -> `Add Folder..` -> 添加`Yaf-PHP`文件路径 -> `open` 74 | ~~~ 75 | 76 | ## 1.5 最终效果图 77 | 78 |

79 | IDE识别 80 |

81 | 82 |

83 | IDE自动补齐 84 |

85 | 86 | # 2 相关链接 87 | 88 | - [Yaf官方文档](http://www.laruence.com/manual/) 89 | - [Yaf源码](https://github.com/laruence/yaf) 90 | - [Yaf Doc](https://github.com/elad-yosifon/php-yaf-doc) 91 | 92 | # 3.待解决问题 93 | 94 | - [ ] 接入travis CI/codecov/lint,内容包含单元测试/测试覆盖率/代码规范校验 95 | - [x] 项目中TODO List清理 96 | - [x] 测试用例完善 97 | - [x] README文档完善 98 | - [x] 加载方式同时支持PSR4和PSR0 99 | - [x] 代码注释完善,包括函数入参出参参数说明,以及每个函数作用说明 100 | -------------------------------------------------------------------------------- /tests/P007Test.php: -------------------------------------------------------------------------------- 1 | [ 25 | 'name' => 'value', 26 | 'dummy' => 'foo', 27 | ], 28 | 'section2' => "laruence", 29 | ]; 30 | 31 | $config1 = new Simple($config, 'section2'); 32 | $this->assertSame([ 33 | 'section1' => [ 34 | 'name' => 'value', 35 | 'dummy' => 'foo', 36 | ], 37 | 'section2' => "laruence", 38 | ], $config1->_config); 39 | 40 | //--------------------------------------- 41 | 42 | $config2 = new Simple($config, 'section1'); 43 | $this->assertTrue($config2->readonly()); 44 | $config2->new = 'value'; 45 | $this->assertFalse(isset($config->new)); 46 | 47 | //--------------------------------------- 48 | 49 | $config3 = new Simple($config); 50 | unset($config); 51 | $this->assertTrue(isset($config3['section2'])); 52 | $config3->new = "value"; 53 | $this->assertFalse($config3->readonly()); 54 | 55 | ob_start(); 56 | foreach ($config3 as $key => $val) { 57 | print_r($key); 58 | print_r("=>"); 59 | print_r($val); 60 | print_r(PHP_EOL); 61 | } 62 | $buf = ob_get_contents(); 63 | ob_end_clean(); 64 | $output = <<Yaf\Config\Simple Object 66 | ( 67 | [_readonly] => 68 | [_config] => Array 69 | ( 70 | [name] => value 71 | [dummy] => foo 72 | ) 73 | 74 | ) 75 | 76 | section2=>laruence 77 | new=>value 78 | 79 | OUTPUT; 80 | $this->assertSame($output, $buf); 81 | 82 | $this->assertSame([ 83 | 'section1'=> [ 84 | 'name' => 'value', 85 | 'dummy' => 'foo' 86 | ], 87 | 'section2' => 'laruence', 88 | 'new' => 'value' 89 | ], $config3->toArray()); 90 | //--------------------------------------- 91 | 92 | $sick = @new Simple(null); 93 | 94 | $this->assertFalse($sick->__isset(1)); 95 | $this->assertFalse($sick->__get(2)); 96 | $sick->total = 1; 97 | $this->assertSame(1, count($sick)); 98 | $this->assertSame(1, $sick->total); 99 | 100 | $sick->total_2 = 2; 101 | $this->assertSame(2, count($sick)); 102 | $this->assertSame(2, $sick->total_2); 103 | } 104 | public function tearDown() 105 | { 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /tests/P008Test.php: -------------------------------------------------------------------------------- 1 | addRoute('simple', $route)->addRoute('super', $sroute); 31 | 32 | ob_start(); 33 | print_r($router); 34 | $content = ob_get_contents(); 35 | ob_end_clean(); 36 | 37 | $expect = << Array 41 | ( 42 | [_default] => Yaf\Route_Static Object 43 | ( 44 | ) 45 | 46 | [simple] => Yaf\Route\Simple Object 47 | ( 48 | [controller:protected] => c 49 | [module:protected] => m 50 | [action:protected] => a 51 | ) 52 | 53 | [super] => Yaf\Route\Supervar Object 54 | ( 55 | [_var_name:protected] => r 56 | ) 57 | 58 | ) 59 | 60 | [_current:protected] => 61 | ) 62 | 63 | EXPECT; 64 | $this->assertSame($content, $expect); 65 | 66 | // =========== test 2 67 | 68 | $this->assertNull($router->getCurrentRoute()); 69 | 70 | // =========== test 3 71 | 72 | ob_start(); 73 | print_r($router->getRoutes()); 74 | $content = ob_get_contents(); 75 | ob_end_clean(); 76 | 77 | $expect = << Yaf\Route_Static Object 81 | ( 82 | ) 83 | 84 | [simple] => Yaf\Route\Simple Object 85 | ( 86 | [controller:protected] => c 87 | [module:protected] => m 88 | [action:protected] => a 89 | ) 90 | 91 | [super] => Yaf\Route\Supervar Object 92 | ( 93 | [_var_name:protected] => r 94 | ) 95 | 96 | ) 97 | 98 | EXPECT; 99 | 100 | $this->assertSame($content, $expect); 101 | 102 | // =========== test 4 103 | 104 | /** @var Simple $route */ 105 | 106 | ob_start(); 107 | print_r($router->getRoute('simple')); 108 | $content = ob_get_contents(); 109 | ob_end_clean(); 110 | 111 | $expect = << c 115 | [module:protected] => m 116 | [action:protected] => a 117 | ) 118 | 119 | EXPECT; 120 | 121 | $this->assertSame($content, $expect); 122 | 123 | // =========== test 5 124 | $this->assertNull($router->getRoute('noexists')); 125 | } 126 | 127 | public function tearDown() 128 | { 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /psr4/Plugin.php: -------------------------------------------------------------------------------- 1 | assertSame('index', $request->module); 28 | $this->assertSame('dummy', $request->controller); 29 | $this->assertSame('index', $request->action); 30 | $this->assertSame('CLI', $request->method); 31 | $this->assertTrue((bool) $request->setParam('name', 'Laruence')); 32 | $this->assertTrue($request->isCli()); 33 | $this->assertFalse($request->isXmlHttpRequest()); 34 | $this->assertFalse($request->isPost()); 35 | $this->assertSame('Laruence', $request->getParam('name')); 36 | $this->assertNull($request->getParam('notexists')); 37 | 38 | //--------------------------------------- 39 | 40 | $catch = false; 41 | try { 42 | $app = new Yaf_Application([ 43 | 'application' => ['directory' => dirname(__FILE__)], 44 | ]); 45 | $app->getDispatcher()->dispatch($request); 46 | } catch (Controller | \Exception $e) { 47 | $catch = true; 48 | $this->assertTrue( 49 | strncmp( 50 | 'Failed opening controller script %scontrollers%cDummy.php: No such file or directory', 51 | $e->getMessage(), 52 | strlen('Failed opening controller script ') 53 | ) === 0 54 | ); 55 | } 56 | $this->assertTrue($catch); 57 | 58 | $this->assertNull($request->get('xxx')); 59 | $this->assertNull($request->getQuery('xxx')); 60 | $this->assertNull($request->getServer('xxx')); 61 | $this->assertNull($request->getPost('xxx')); 62 | //$this->assertNull($request->getCookie('xxx')); 63 | $this->assertNull($request->getEnv('xxx')); 64 | 65 | // test 1 ------default value------- 66 | $this->assertSame('123', $request->get('xxx', '123')); 67 | $default = new \stdClass(); 68 | $this->assertSame($default, $request->getQuery('xxx', $default)); 69 | $this->assertSame([], $request->getServer('xxx', [])); 70 | $this->assertNull($request->getPost('xxx', null)); 71 | $this->assertFalse($request->getCookie('xxx', false)); 72 | $this->assertSame('2.13232', $request->getEnv('xxx', '2.13232')); 73 | 74 | // test 2 ------params------- 75 | $this->assertNull($request->setParam("xxxx")); 76 | $this->assertNull($request->getParam("xxxx")); 77 | $this->assertSame([ 78 | 'name' => 'Laruence' 79 | ], $request->getParams()); 80 | } 81 | 82 | public function tearDown() 83 | { 84 | ini_set('yaf.use_namespace', null); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /psr0/Plugin.php: -------------------------------------------------------------------------------- 1 | disableView(); 19 | $this->forward('dummy'); 20 | } 21 | 22 | public function dummyAction() 23 | { 24 | Dispatcher::getInstance()->enableView(); 25 | } 26 | } 27 | 28 | /** 29 | * Check for Yaf_View_Simple with predefined template dir 30 | * 31 | * @run ./vendor/bin/phpunit --bootstrap ./tests/bootstrap.php ./tests/P033Test.php 32 | */ 33 | class P033Test extends Base 34 | { 35 | public function setUp() 36 | { 37 | parent::setUp(); 38 | } 39 | 40 | /** 41 | * @throws \Exception 42 | */ 43 | public function test() 44 | { 45 | $config = [ 46 | 'application' => [ 47 | 'directory' => realpath(__DIR__), 48 | 'dispatcher' => [ 49 | 'catchException' => 0, 50 | 'throwException' => 1, 51 | ], 52 | 'modules' => 'module', 53 | ], 54 | ]; 55 | 56 | $app = new Application($config); 57 | $request = new Http('/module/controller/action'); 58 | 59 | // ============ test 1 60 | $exception = false; 61 | try { 62 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 63 | } catch (\Exception $e) { 64 | $exception = true; 65 | $this->assertTrue(stripos($e->getMessage(), 'Failed opening template') !== false 66 | && stripos($e->getMessage(), 'modules/Module/views/controller/Action.phtml') !== false); 67 | } 68 | $this->assertTrue($exception); 69 | 70 | // ============ test 2 71 | $exception = false; 72 | $view = new Simple(__DIR__ . '/no-exists'); 73 | $app->getDispatcher()->setView($view); 74 | try { 75 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 76 | } catch (\Exception $e) { 77 | $exception = true; 78 | $this->assertTrue(stripos($e->getMessage(), 'Failed opening template') !== false 79 | && stripos($e->getMessage(), 'no-exists/controller/Action.phtml') !== false); 80 | } 81 | $this->assertTrue($exception); 82 | 83 | // TODO 和实际有点8太一样 84 | // ============ test 3 85 | $exception = false; 86 | $request = new Http('/module/controller/index'); 87 | try { 88 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 89 | } catch (\Exception $e) { 90 | $exception = true; 91 | $this->assertTrue(stripos($e->getMessage(), 'Failed opening template') !== false 92 | && stripos($e->getMessage(), 'controller/Dummy.phtml') !== false); 93 | } 94 | 95 | $this->assertTrue($exception); 96 | } 97 | 98 | public function tearDown() 99 | { 100 | parent::setUp(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /tests/P041Test.php: -------------------------------------------------------------------------------- 1 | forward('controller', 'dummy'); 19 | 20 | /* don't auto-render */ 21 | return false; 22 | } 23 | 24 | public function dummyAction() 25 | { 26 | Dispatcher::getInstance()->enableView(); 27 | } 28 | } 29 | 30 | /** 31 | * Check for controller return false preventing auto-renderring 32 | * 33 | * @run ./vendor/bin/phpunit --bootstrap ./tests/bootstrap.php ./tests/P041Test.php 34 | */ 35 | class P041Test extends Base 36 | { 37 | public function setUp() 38 | { 39 | parent::setUp(); 40 | } 41 | 42 | /** 43 | * @throws Exception 44 | */ 45 | public function test() 46 | { 47 | $config = [ 48 | 'application' => [ 49 | 'directory' => realpath(__DIR__), 50 | 'dispatcher' => [ 51 | 'catchException' => 0, 52 | 'throwException' => 1, 53 | ], 54 | 'modules' => 'module', 55 | ], 56 | ]; 57 | 58 | $app = new Application($config); 59 | $request = new Http('/module/controller/action'); 60 | 61 | // ============ test 1 62 | $exception = false; 63 | try { 64 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 65 | } catch (\Exception $e) { 66 | $exception = true; 67 | $this->assertTrue(stripos($e->getMessage(), 'Failed opening template') !== false 68 | && stripos($e->getMessage(), 'modules/Module/views/controller/Action.phtml') !== false); 69 | } 70 | $this->assertTrue($exception); 71 | 72 | // ============ test 2 73 | $exception = false; 74 | $view = new Simple(__DIR__ . '/no-exists'); 75 | $app->getDispatcher()->setView($view); 76 | try { 77 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 78 | } catch (\Exception $e) { 79 | $exception = true; 80 | $this->assertTrue(stripos($e->getMessage(), 'Failed opening template') !== false 81 | && stripos($e->getMessage(), 'no-exists/controller/Action.phtml') !== false); 82 | } 83 | $this->assertTrue($exception); 84 | 85 | // TODO 和实际有点8太一样 86 | // ============ test 3 87 | $exception = false; 88 | $request = new Http('/module/controller/index'); 89 | try { 90 | $app->getDispatcher()->returnResponse(false)->dispatch($request); 91 | } catch (\Exception $e) { 92 | $exception = true; 93 | $this->assertTrue(stripos($e->getMessage(), 'Failed opening template') !== false 94 | && stripos($e->getMessage(), 'controller/Dummy.phtml') !== false); 95 | } 96 | 97 | $this->assertTrue($exception); 98 | } 99 | 100 | public function tearDown() 101 | { 102 | parent::setUp(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /psr0/routes/Supervar.php: -------------------------------------------------------------------------------- 1 | _var_name = $var; 32 | } 33 | 34 | /** 35 | * @link https://www.php.net/manual/en/yaf-route-supervar.route.php 36 | * 37 | * @param Request_Abstract $request 38 | * @return bool 39 | * @throws \ReflectionException 40 | */ 41 | public function route($request) 42 | { 43 | if (!($request instanceof Request_Abstract)) { 44 | return; 45 | } 46 | 47 | return (bool) $this->_route($request); 48 | } 49 | 50 | /** 51 | * @link https://www.php.net/manual/en/yaf-route-supervar.assemble.php 52 | * 53 | * @param array $info 54 | * @param array|null $query 55 | * @return null|string 56 | * @throws \Exception 57 | */ 58 | public function assemble(array $info, array $query = null) 59 | { 60 | $str = $this->_assemble($info, $query); 61 | 62 | return is_null($str) ? $str : strval($str); 63 | } 64 | 65 | // ================================================== 内部方法 ================================================== 66 | 67 | /** 68 | * @param array $info 69 | * @param array $query 70 | * @return null|string 71 | * @throws \Exception 72 | */ 73 | private function _assemble(array $info, array $query) 74 | { 75 | $uri = ''; 76 | $pname = $this->_var_name; 77 | 78 | do { 79 | $uri .= '?'; 80 | $uri .= $pname; 81 | $uri .= '='; 82 | 83 | $zv = $info[Route_Interface::YAF_ROUTE_ASSEMBLE_MOUDLE_FORMAT]; 84 | if (!is_null($zv)) { 85 | $uri .= '/' . $zv; 86 | } 87 | 88 | $zv = $info[Route_Interface::YAF_ROUTE_ASSEMBLE_CONTROLLER_FORMAT]; 89 | if (is_null($zv)) { 90 | yaf_trigger_error(TYPE_ERROR, "You need to specify the controller by ':c'"); 91 | break; 92 | } 93 | $uri .= '/' . $zv; 94 | 95 | $zv = $info[Route_Interface::YAF_ROUTE_ASSEMBLE_ACTION_FORMAT]; 96 | if (is_null($zv)) { 97 | yaf_trigger_error(TYPE_ERROR, "You need to specify the action by ':a'"); 98 | break; 99 | } 100 | $uri .= '/' . $zv; 101 | 102 | if ($query && is_array($query)) { 103 | $uri .= '&' . http_build_query($query); 104 | } 105 | 106 | return $uri; 107 | } while (0); 108 | 109 | return null; 110 | } 111 | 112 | /** 113 | * @param Request_Abstract $request 114 | * @return int 115 | * @throws \ReflectionException 116 | */ 117 | private function _route(Request_Abstract $request) 118 | { 119 | $varname = $this->_var_name; 120 | $uri = Request_Abstract::_queryEx('GET', $varname); 121 | 122 | if (!$uri) { 123 | return 0; 124 | } 125 | 126 | $pathinfoRouteMethod = new \ReflectionMethod(Route_Static::class, '_pathInfoRoute'); 127 | $pathinfoRouteMethod->invoke(null, $request, $uri); 128 | return 1; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /psr4/routes/Supervar.php: -------------------------------------------------------------------------------- 1 | _var_name = $var; 33 | } 34 | 35 | /** 36 | * @link https://www.php.net/manual/en/yaf-route-supervar.route.php 37 | * 38 | * @param Request_Abstract $request 39 | * @return bool 40 | * @throws \ReflectionException 41 | */ 42 | public function route($request) 43 | { 44 | if (!($request instanceof Request_Abstract)) { 45 | return; 46 | } 47 | 48 | return (bool) $this->_route($request); 49 | } 50 | 51 | /** 52 | * @link https://www.php.net/manual/en/yaf-route-supervar.assemble.php 53 | * 54 | * @param array $info 55 | * @param array|null $query 56 | * @return null|string 57 | * @throws \Exception 58 | */ 59 | public function assemble(array $info, array $query = null) 60 | { 61 | $str = $this->_assemble($info, $query); 62 | 63 | return is_null($str) ? $str : strval($str); 64 | } 65 | 66 | // ================================================== 内部方法 ================================================== 67 | 68 | /** 69 | * @param array $info 70 | * @param array $query 71 | * @return null|string 72 | * @throws \Exception 73 | */ 74 | private function _assemble(array $info, array $query) 75 | { 76 | $uri = ''; 77 | $pname = $this->_var_name; 78 | 79 | do { 80 | $uri .= '?'; 81 | $uri .= $pname; 82 | $uri .= '='; 83 | 84 | $zv = $info[Route_Interface::YAF_ROUTE_ASSEMBLE_MOUDLE_FORMAT] ?? null; 85 | if (!is_null($zv)) { 86 | $uri .= '/' . $zv; 87 | } 88 | 89 | $zv = $info[Route_Interface::YAF_ROUTE_ASSEMBLE_CONTROLLER_FORMAT] ?? null; 90 | if (is_null($zv)) { 91 | yaf_trigger_error(TYPE_ERROR, "You need to specify the controller by ':c'"); 92 | break; 93 | } 94 | $uri .= '/' . $zv; 95 | 96 | $zv = $info[Route_Interface::YAF_ROUTE_ASSEMBLE_ACTION_FORMAT] ?? null; 97 | if (is_null($zv)) { 98 | yaf_trigger_error(TYPE_ERROR, "You need to specify the action by ':a'"); 99 | break; 100 | } 101 | $uri .= '/' . $zv; 102 | 103 | if ($query && is_array($query)) { 104 | $uri .= '&' . http_build_query($query); 105 | } 106 | 107 | return $uri; 108 | } while (0); 109 | 110 | return null; 111 | } 112 | 113 | /** 114 | * @param Request_Abstract $request 115 | * @return int 116 | * @throws \ReflectionException 117 | */ 118 | private function _route(Request_Abstract $request) 119 | { 120 | $varname = $this->_var_name; 121 | $uri = Request_Abstract::_queryEx('GET', $varname); 122 | 123 | if (!$uri) { 124 | return 0; 125 | } 126 | 127 | $pathinfoRouteMethod = new \ReflectionMethod(Route_Static::class, '_pathInfoRoute'); 128 | $pathinfoRouteMethod->invoke(null, $request, $uri); 129 | return 1; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /tests/P036Test.php: -------------------------------------------------------------------------------- 1 | [ 35 | 'directory' => '/tmp/', 36 | 'modules' => 'Index,My', 37 | ], 38 | ]; 39 | 40 | $app = new Application($config); 41 | $route = Dispatcher::getInstance()->getRouter(); 42 | 43 | $expect = << c=> a=> 45 | /foo : m=> c=>foo a=> 46 | /foo/ : m=> c=>foo a=> 47 | /foo///bar : m=> c=>foo a=>bar 48 | foo/bar : m=> c=>foo a=>bar 49 | /foo/bar/ : m=> c=>foo a=>bar 50 | /foo/bar/dummy : m=> c=>foo a=>bar args=>dummy->, 51 | /foo///bar/dummy/ : m=> c=>foo a=>bar args=>dummy->, 52 | foo/bar/dummy/ : m=> c=>foo a=>bar args=>dummy->, 53 | /my : m=> c=>my a=> 54 | /my/ : m=> c=>my a=> 55 | /my/foo : m=> c=>my a=>foo 56 | /my/foo/ : m=> c=>my a=>foo 57 | my/foo/bar : m=>my c=>foo a=>bar 58 | my/foo/bar/ : m=>my c=>foo a=>bar 59 | /m/index/index : m=> c=>m a=>index args=>index->, 60 | /my/foo/bar/dummy/1 : m=>my c=>foo a=>bar args=>dummy->1, 61 | my/foo/bar/dummy/1/a/2///// : m=>my c=>foo a=>bar args=>dummy->1,a->2, 62 | /my/index/index : m=>my c=>index a=>index 63 | my/index : m=> c=>my a=>index 64 | /foo/index : m=> c=>foo a=>index 65 | index/foo : m=> c=>index a=>foo 66 | 67 | EXPECT; 68 | 69 | ob_start(); 70 | foreach ($urls as $url) { 71 | $req = new Http($url); 72 | $route->route($req); 73 | echo $url, ' : ', 'm=>', $req->getModuleName(), ' c=>', $req->getControllerName(), ' a=>', $req->getActionName(); 74 | if (($args = $req->getParams())) { 75 | echo ' args=>'; 76 | foreach ($args as $k => $v) { 77 | echo $k , '->', $v , ','; 78 | } 79 | } 80 | echo PHP_EOL; 81 | } 82 | $actual = ob_get_contents(); 83 | ob_end_clean(); 84 | 85 | // $this->assertSame($expect, $actual); 86 | 87 | $expect = << c=> a=> 89 | /foo : m=> c=> a=>foo 90 | /foo/ : m=> c=> a=>foo 91 | /my : m=> c=>my a=> 92 | /my/ : m=> c=>my a=> 93 | /my/foo : m=> c=>my a=>foo 94 | /my//foo/ : m=> c=>my a=>foo 95 | 96 | EXPECT; 97 | 98 | // ===================== test 2 99 | 100 | YAF_G('yaf.action_prefer', 1); 101 | $urls = [ 102 | '/', '/foo', '/foo/', 103 | '/my', '/my/', '/my/foo', '/my//foo/', 104 | ]; 105 | 106 | ob_start(); 107 | foreach ($urls as $url) { 108 | $req = new Http($url); 109 | $route->route($req); 110 | echo $url, ' : ', 'm=>', $req->getModuleName(), ' c=>', $req->getControllerName(), ' a=>', $req->getActionName(); 111 | if (($args = $req->getParams())) { 112 | echo ' args=>'; 113 | foreach ($args as $k => $v) { 114 | echo $k , '->', $v , ','; 115 | } 116 | } 117 | echo PHP_EOL; 118 | } 119 | $actual = ob_get_contents(); 120 | ob_end_clean(); 121 | 122 | $this->assertSame($expect, $actual); 123 | } 124 | 125 | public function tearDown() 126 | { 127 | parent::setUp(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /psr0/routes/Simple.php: -------------------------------------------------------------------------------- 1 | module = $module; 36 | $this->controller = $controller; 37 | $this->action = $action; 38 | } 39 | 40 | /** 41 | * @link https://www.php.net/manual/en/yaf-route-simple.route.php 42 | * 43 | * @param Request_Abstract $request 44 | * @return bool 45 | */ 46 | public function route(Request_Abstract $request) 47 | { 48 | return (bool) $this->_route($request); 49 | } 50 | 51 | /** 52 | * @link https://www.php.net/manual/en/yaf-route-simple.assemble.php 53 | * 54 | * @param array $info 55 | * @param array|null $query 56 | * @return null|string 57 | * @throws \Exception 58 | */ 59 | public function assemble(array $info, array $query = null) 60 | { 61 | $str = $this->_assemble($info, $query); 62 | 63 | return $str; 64 | } 65 | 66 | // ================================================== 内部方法 ================================================== 67 | 68 | /** 69 | * @param array $info 70 | * @param array $query 71 | * @return null|string 72 | * @throws \Exception 73 | */ 74 | private function _assemble(array $info, array $query): ?string 75 | { 76 | $uri = '?'; 77 | 78 | $nmodule = $this->module; 79 | $ncontroller = $this->controller; 80 | $naction = $this->action; 81 | 82 | do { 83 | if (!is_null($zv = $info[self::YAF_ROUTE_ASSEMBLE_MOUDLE_FORMAT])) { 84 | $uri .= $nmodule . '=' . $zv . '&'; 85 | } 86 | 87 | if (is_null($zv = $info[self::YAF_ROUTE_ASSEMBLE_CONTROLLER_FORMAT])) { 88 | yaf_trigger_error(TYPE_ERROR, "You need to specify the controller by ':c'"); 89 | break; 90 | } 91 | 92 | $uri .= $ncontroller . '=' . $zv . '&'; 93 | 94 | if (is_null($zv = $info[self::YAF_ROUTE_ASSEMBLE_ACTION_FORMAT])) { 95 | yaf_trigger_error(TYPE_ERROR, "You need to specify the action by ':a'"); 96 | break; 97 | } 98 | 99 | $uri .= $naction . '=' . $zv; 100 | 101 | if (!empty($query) && is_array($query)) { 102 | $uri .= '&' . http_build_query($query); 103 | } 104 | 105 | return $uri; 106 | } while (0); 107 | 108 | return null; 109 | } 110 | 111 | private function _route(Request_Abstract $request) 112 | { 113 | $nmodule = $this->module; 114 | $ncontroller = $this->controller; 115 | $naction = $this->action; 116 | 117 | $module = Request_Abstract::_queryEx('GET', $nmodule); 118 | $controller = Request_Abstract::_queryEx('GET', $ncontroller); 119 | $action = Request_Abstract::_queryEx('GET', $naction); 120 | 121 | if ($module && is_string($module) && Application::isModuleName($module)) { 122 | $request->setModuleName($module); 123 | } 124 | 125 | if ($controller) { 126 | $request->setControllerName($controller); 127 | } 128 | 129 | if ($action) { 130 | $request->setActionName($action); 131 | } 132 | 133 | return 1; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /psr4/routes/Interface.php: -------------------------------------------------------------------------------- 1 |