Skip to content

Instantly share code, notes, and snippets.

@suin
Created March 5, 2012 11:25
Show Gist options
  • Save suin/1977931 to your computer and use it in GitHub Desktop.
Save suin/1977931 to your computer and use it in GitHub Desktop.
【PHPUnitに詳しい人教えて!】 コンストラクタのテスト方法 ref: http://qiita.com/items/3008
<?php
class PDOTest extends \PHPUnit_Framework_TestCase
{
public function test__construct()
{
$pdo = $this
->getMockBuilder('\Suin\PDO')
->setMethods(array('_getDefaultAttributes'))
->disableOriginalConstructor()
->getMock();
$pdo
->expects($this->once())
->method('_getDefaultAttributes')
->will($this->returnValue(array()));
$pdo->__construct('mysql:host=127.0.0.1;dbname=testdb;charset=utf8;', 'root', 'root');
}
}
$ phpunit PDOTest.php
PHPUnit 3.6.10 by Sebastian Bergmann.
E
Time: 0 seconds, Memory: 3.00Mb
There was 1 error:
1) Suin\PDOTest::test__construct
PDOException: You cannot serialize or unserialize PDO instances
/Users/suin/Desktop/PDOTest.php:44
/Users/suin/.phpenv/versions/5.4.0pear/bin/phpunit:46
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment