This is the topic for wUnit extension.
If you have questions or found a bug let me know.
Page 1 of 1
[Extension] wUnit Functional testing without Selenium
#2
Posted 31 January 2012 - 03:57 PM
Thank you for this extension!
I have made all under the instructions, but no result.
Output:
Help please!
I have made all under the instructions, but no result.
Output:
c:\...\tests>phpunit unit PHPUnit 3.6.7 by Sebastian Bergmann. Configuration read from C:\...\tests\phpunit.xml .. Time: 3 seconds, Memory: 8.75Mb OK (2 tests, 4 assertions) c:\...\tests>phpunit functional c:\...\tests>phpunit functional/AccessControllerTest.php c:\...\tests>
Help please!
#4
Posted 31 January 2012 - 04:24 PM
Could you show me your bootstrap.php for tests ? I guess you use Yii::createWebApplication() instead of WUnit::createWebApplication().
If you create application with Yii::createWebApplication() and try to call action with redirect you will get no output, because redirect() contains 'exit;', which terminate script execution at all, no matter test it or not. That's why we had to override some method with exit by WUnit::createWebApplication().
If you create application with Yii::createWebApplication() and try to call action with redirect you will get no output, because redirect() contains 'exit;', which terminate script execution at all, no matter test it or not. That's why we had to override some method with exit by WUnit::createWebApplication().
#5
Posted 31 January 2012 - 04:45 PM
You're right. My mistake.
Nevertheless, requests are processed not as I expect.
For example logout:
Output:
But login:
All right.
Nevertheless, requests are processed not as I expect.
For example logout:
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/logout');
$this->assertTrue($crawler->filter('html:contains("ERP-system")')->count() > 0);
}Output:
AccessControllerTest::testIndex() Failed asserting that false is true.
But login:
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$this->assertTrue($crawler->filter('html:contains("ERP-system")')->count() > 0);
}All right.
#6
Posted 31 January 2012 - 04:49 PM
Hum... What about:
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/logout');
$crawler = $client->followRedirect();
$this->assertTrue($crawler->filter('html:contains("ERP-system")')->count() > 0);
}
#7
Posted 01 February 2012 - 10:45 AM
New version released.
Changelog
0.2.1
0.2
Changelog
0.2.1
- Fixed issues in unix-like systems
- Enabled followRedirects by default (as per documentation)
0.2
- Added classes autoloader so XPathExpr error should not appear any more
- Fixed exception with YiiExitApplication
- Modified manual to specify printerFile into phpunit.xml
#8
Posted 01 February 2012 - 10:48 AM
Levka,
Please, update extension with latest version, and your wouldn't require followRedirect() calls.
Here is unit tests for wunit related to login/logout:
Please, update extension with latest version, and your wouldn't require followRedirect() calls.
Here is unit tests for wunit related to login/logout:
class LoginTest extends \PHPUnit_Framework_TestCase
{
protected static $wunit;
public static function setUpBeforeClass()
{
static::$wunit = new WUnit();
static::$wunit->init();
}
public function testLoginPage()
{
$client = static::$wunit->createClient();
$crawler = $client->request('GET', '/test/login');
$this->assertTrue($crawler->filter('html:contains("Please fill out the following form with your login credentials")')->count() > 0);
}
public function testLoginForm()
{
$client = static::$wunit->createClient();
$usermame = "demo";
$password = "demo";
$crawler = $client->request('GET', '/test/index');
$this->assertTrue($crawler->filter('html:contains("You are not loged in")')->count() > 0);
$this->assertTrue($this->login($client, $usermame, $password)->filter('html:contains("You are loged in as demo")')->count() > 0);
$client->back();
$crawler = $client->request('GET', '/test/index');
$this->assertTrue($crawler->filter('html:contains("You are loged in as demo")')->count() > 0);
$crawler = $client->request('GET', '/test/logout');
$this->assertTrue($crawler->filter('html:contains("You are not loged in")')->count() > 0);
$crawler = $client->request('GET', '/test/index');
$this->assertTrue($this->login($client, 'demo', 'demo')->filter('html:contains("You are loged in as demo")')->count() > 0);
}
private function login($client, $username, $password){
$crawler = $client->request('GET', '/test/login');
$form = $crawler->selectButton('Login')->form();
$form['LoginForm[username]'] = $username;
$form['LoginForm[password]'] = $password;
$form['LoginForm[rememberMe]']->tick();
return $client->submit($form);
}
}
#9
Posted 03 February 2012 - 12:58 PM
That's great!
No problems now with autoredirect.
Does may this extension analyze messageboxes?
No problems now with autoredirect.
Does may this extension analyze messageboxes?
#10
Posted 13 March 2012 - 01:03 AM
Thanks for this great extension.
Can you add this comment in top of function createClient (WUnitTestCase.php) ?
This will allow netbeans to give autocomplete hint when you typed something like this:
Edit: add this issues in github
Can you add this comment in top of function createClient (WUnitTestCase.php) ?
/**
* Create HttpKernel Client
* @return WUnit\HttpKernel\Client
*/
This will allow netbeans to give autocomplete hint when you typed something like this:
$client = static::createClient(); $crawler = $client-> // ^^^ autocomplete hints appear
Edit: add this issues in github
Share this topic:
Page 1 of 1

Help












