Skip to content

Commit

Permalink
Addint more unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andres.gutierrez committed Mar 3, 2012
1 parent a4cfc9b commit 49f9388
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ php:
- 5.3

before_script:
- cd release/
- cd dev/
- sh -c "phpize && ./configure --enable-phalcon && make && sudo make install"
- echo "extension=phalcon.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
- cd ..

script: phpunit -c unit-tests/phpunit.xml

Expand Down
33 changes: 33 additions & 0 deletions unit-tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,37 @@ public function testDispatcher(){

}

public function testEvents(){

$dispatcher = new Phalcon_Dispatcher();

$controllersDir = 'unit-tests/controllers/';
$dispatcher->setControllersDir($controllersDir);
$this->assertEquals($dispatcher->getControllersDir(), $controllersDir);

$request = Phalcon_Request::getInstance();
$this->assertInstanceOf('Phalcon_Request', $request);

$response = Phalcon_Response::getInstance();
$this->assertInstanceOf('Phalcon_Response', $response);

$dispatcher->setControllerName('test5');
$dispatcher->setActionName('notexists');
$dispatcher->setParams(array());
$dispatcher->dispatch($request, $response);
$value = $dispatcher->getActionName();
$this->assertEquals($value, 'notexists');

$value = $dispatcher->getReturnedValue();
$this->assertEquals($value, 'not-found');

$dispatcher->setControllerName('test6');
$dispatcher->setActionName('index');
$dispatcher->setParams(array());
$dispatcher->dispatch($request, $response);
$value = $dispatcher->getReturnedValue();
$this->assertEquals($value, false);

}

}
File renamed without changes.
27 changes: 27 additions & 0 deletions unit-tests/InitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/

class InitTest extends PHPUnit_Framework_TestCase {

public function testExtensionLoaded(){
$this->assertTrue(in_array('phalcon', get_loaded_extensions()));
}

}
59 changes: 59 additions & 0 deletions unit-tests/UtilsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/

class UtilsTest extends PHPUnit_Framework_TestCase {

public function testCamelize(){
$camelizeTests = array (
'camelize' => 'Camelize',
'CameLiZe' => 'Camelize',
'cAmeLize' => 'Camelize',
'_camelize' => 'Camelize',
'123camelize' => '123camelize',
'c_a_m_e_l_i_z_e' => 'CAMELIZE',
'Camelize' => 'Camelize',
'camel_ize' => 'CamelIze',
'CameLize' => 'Camelize',
);
foreach($camelizeTests as $str => $camelized){
$this->assertEquals($camelized, Phalcon_Utils::camelize($str));
}

}

public function testUncamelize(){
$uncamelizeTests = array (
'camelize' => 'camelize',
'CameLiZe' => 'came_li_ze',
'cAmeLize' => 'c_ame_lize',
'_camelize' => '_camelize',
'123camelize' => '123camelize',
'c_a_m_e_l_i_z_e' => 'c_a_m_e_l_i_z_e',
'Camelize' => 'camelize',
'camel_ize' => 'camel_ize',
'CameLize' => 'came_lize',
);
foreach($uncamelizeTests as $str => $camelized){
$this->assertEquals($camelized, Phalcon_Utils::uncamelize($str));
}
}


}
2 changes: 2 additions & 0 deletions unit-tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
syntaxCheck="false">
<testsuites>
<testsuite name="Phalcon PHP Framework">
<file>unit-tests/InitTest.php</file>
<file>unit-tests/UtilsTest.php</file>
<file>unit-tests/ConfigTest.php</file>
<file>unit-tests/FilterTest.php</file>
<file>unit-tests/RequestTest.php</file>
Expand Down

0 comments on commit 49f9388

Please sign in to comment.