phpunit

PHPUnit, Using class consts to change State

∥☆過路亽.° 提交于 2019-12-12 14:03:04
问题 I'm learning Zend and also PHPUnit. Here is what I have below public function changeToIllegalState() { return array( array( Application_Model_SomeModel::FAIL ), array( Application_Model_SomeModel::SUCCESS ) ); } /** * @dataProvider changeToIllegalState * @expectedException IllegalStateChangeException */ public function testIllegalStateChangeGeneratesException( $state ) { $mapper = new Application_Model_Mapper_SomeModel(); $model = new Application_Model_SomeModel(); $model->changeState( $state

Laravel API Test - How to test API that has external API call

試著忘記壹切 提交于 2019-12-12 13:07:49
问题 My API code public function store (Request $request, $profileId) { $all = $request->all(); $token = AccessToken::with('users')->where('access_token',$request->input('access_token'))->first(); if($token && $token->users->isOwnProfile($profileId)) { $rules = [ 'access_token' => 'required', 'title' => 'required', 'description' => 'required', 'file_id' => 'required', 'audience_control' => 'required|in:' . join(',', PostRepository::$AUDIENCE_CONTROL), 'tags' => 'required', ]; $validator =

PHPUnit and Zend Framework assertRedirectTo() issue

穿精又带淫゛_ 提交于 2019-12-12 12:38:08
问题 I'm having an issue with assertRedirectTo() in a test I have created, below is the code I have used: public function testLoggedInIndexAction() { $this->dispatch('/'); $this->assertController('index'); $this->resetResponse(); $this->request->setPost(array( 'type' => 'login', 'username' => 'root', 'password' => 'asdasd', )); $this->request->setMethod('POST'); $this->dispatch('/'); $this->assertRedirectTo('/feed/'); } You log in through / (index.php/) and submit post details there and the it

LogicException: Missing default data in Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector

泪湿孤枕 提交于 2019-12-12 12:25:29
问题 Getting this exception in Symfony 2.5.5 with Swiftmailer 5.3.0. I'm following the cookbook example exactly. The error is thrown when calling MessageDataCollector#getMessages() : // Check that an e-mail was sent $this->assertEquals(1, $mailCollector->getMessageCount()); $collectedMessages = $mailCollector->getMessages(); $message = $collectedMessages[0]; The message count assertion is also failing with a value of zero. As far as I can tell the collector is failing to do any actual collecting

Pass by reference in a callback when mocking in PHPUnit

冷暖自知 提交于 2019-12-12 12:08:36
问题 I have an interface I want to mock, and mock the behaviour of one of it's methods. So I have created a callback that mocks the behaviour very simply. This test passes if I create a new object that is based on this interface, but I would like to mock the interface. The mocked setUp method is being called fine, and calling getVar('testing') in my callback returns the value. However my assertion fails, because that value isn't available. It seems that you can't do this in PHPUnit? Unless I am

phpunit testing expectedException not working

我的未来我决定 提交于 2019-12-12 11:03:48
问题 I am trying to test my class for InvalidArgumentException but I get Tests\BarTest::should_receive_parameter Missing argument 1 for Itdc\Foo\Bar::__construct(), called in /mypath/foo/tests/BarTest.php on line 10 and defined This is the test (BarTest.php) file I use: <?php namespace Tests; use Itdc\Foo\Bar; class BarTest extends \PHPUnit_Framework_TestCase { /** @test */ public function should_receive_parameter() { $this->setExpectedException('Exception'); $id = new Bar; } } This is Bar class:

Zend_Controller_Router_Exception: Route default is not defined

丶灬走出姿态 提交于 2019-12-12 10:54:05
问题 I'm trying to test a controller. Zend Tool has generated the following code: class Default_CarrinhoControllerTest extends Zend_Test_PHPUnit_ControllerTestCase { public function setUp() { $this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); parent::setUp(); } public function testIndexAction() { $params = array('action' => 'index', 'controller' => 'Carrinho', 'module' => 'default'); $urlParams = $this->urlizeOptions($params); $url = $this->url

PHPUnit problem - no error messages

做~自己de王妃 提交于 2019-12-12 10:30:10
问题 I've been trying to solve this problem for quite some time. I have a simple PHPUnit test case with 2 tests. When I run it, I get this output: PHPUnit 3.5.14 by Sebastian Bergmann. . So the first assertion runs, passes. The second assertion, however, causes some PHP error (exception or something), and PHPUnit just dies without any info about what could have gone wrong. Here is my phpunit.xml: <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false"

Testing coverage with PHPUnit and PDO

帅比萌擦擦* 提交于 2019-12-12 10:27:46
问题 As an exercise, I'm trying to reach 100% code coverage using PHPUnit, this is almost there, but it's the error bits which I've found difficult. I have an example class which I has a similar issue to my real code, the exact code is not the issue, but the behaviour is the same. class DBAccess { private $db; public function __construct( \PDO $db ) { $this->db = $db; } public function select () { $data = false; if ( $stmt = $this->db->prepare("select * from user") ){ if ( $stmt->execute() ){

How to install PEAR with EasyPHP 5.3.8?

倖福魔咒の 提交于 2019-12-12 08:14:52
问题 I'm learning Yii and following ebook written by Jeffrey Winesett, the application is built upon TDD. So I need to install PHPUnit to write unit test, which leads me to posts help installing PEAR for my Windows 7 (ref. link 1, link 2). And in those above sites, the author keep telling to use go-pear.bat which doesn't exists in my EasyPHP 5.3.8 which also be the latest version at the time of speaking. Even in this EasyPHP forum post we cannot find the answer. So the question is: How to install