phpunit

Is it possible, using PHPUnit mock objects, to expect a call to a magic __call() method?

人走茶凉 提交于 2019-12-20 10:26:40
问题 I've got a mock object in a test. The real object, PageRepository, implements a magic method using __call(), so if you call $pageRepository->findOneByXXXX($value_of_field_XXXX), it will search the database for records matching that parameter. Is there a way to mock that method? The real method call would look something like this: $homepage = $pageRepository->findOneBySlug('homepage'); The test would look like this: $mockPageRepository->expects($this->any()) ->method('findOneBySlug') ->will(

First Shot at Testing Laravel 4 apps (PHPSpec/BDD vs. PHPUnit/TDD)

戏子无情 提交于 2019-12-20 09:56:18
问题 I have been wrestling with this question for far too long now. I know I need to just jump into one or the other since they are both obviously viable/useful tools, but have been stuck on the fence, researching both, for weeks. PHPUnit vs. PHPSpec - Which one may lead to better long-term maintainability and programming practices? I have talked to several seasoned PHPUnit -> PHPspec converts/users who now swear by PHPspec, claiming that it promotes better design thanks to its BDD approach.

PHP Testing, for Procedural Code

依然范特西╮ 提交于 2019-12-20 09:31:08
问题 Is there any way of testing procedural code? I have been looking at PHPUnit which seems like a great way of creating automated tests. However, it seems to be geared towards object oriented code, are there any alternatives for procedural code? Or should I convert the website to object oriented before attempting to test the website? This may take a while which is a bit of a problem as I don't have a lot of time to waste. Thanks, Daniel. 回答1: You can test procedural code with PHPUnit. Unit tests

Remove “Remaining deprecation notices” in Symfony 2.8

拥有回忆 提交于 2019-12-20 08:46:52
问题 I'm new on Symfony and PHPUnit. I would like to run some tests, there are a lot of deprecation notices. But it does not matter because I'll stay on Symfony 2.8 for now. Do you know if it's possible to remove them? I try to find out by myself, but it's not working, have you got some ideas for me folks ? How to remove the deprecation warnings in Symfony 2.7? Disable deprecated warning in Symfony 2(.7) EDIT : Reference to the answer of @LBA My screenshot is not really about the error of the

How do I use PHPUnit with CodeIgniter?

浪尽此生 提交于 2019-12-20 08:18:19
问题 I have read and read articles on PHPUnit, SimpleTest, and other Unit Testing frameworks. They all sound so great! I finally got PHPUnit working with Codeigniter thanks to https://bitbucket.org/kenjis/my-ciunit/overview Now my question is, how do I use it? Every tutorial I see has some abstract use like assertEquals(2, 1+1) or: public function testSpeakWithParams() { $hello = new SayHello('Marco'); $this->assertEquals("Hello Marco!", $hello->speak()); } That is great if I had a function that

How do I use PHPUnit with CodeIgniter?

拟墨画扇 提交于 2019-12-20 08:18:12
问题 I have read and read articles on PHPUnit, SimpleTest, and other Unit Testing frameworks. They all sound so great! I finally got PHPUnit working with Codeigniter thanks to https://bitbucket.org/kenjis/my-ciunit/overview Now my question is, how do I use it? Every tutorial I see has some abstract use like assertEquals(2, 1+1) or: public function testSpeakWithParams() { $hello = new SayHello('Marco'); $this->assertEquals("Hello Marco!", $hello->speak()); } That is great if I had a function that

How do I write unit tests in PHP with a procedural codebase?

久未见 提交于 2019-12-20 08:03:51
问题 I'm mostly convinced of the benefits of unit testing, and I would like to start applying the concept to a large existing codebase written in PHP. Less than 10% of this code is object-oriented. I've looked at several unit testing frameworks (PHPUnit, SimpleTest, and phpt). However, I haven't found examples for any of these that test procedural code. What's the best framework for my situation and are there any examples of unit testing PHP using non-OOP code? 回答1: You can unit-test procedural

PHPUnit working in IDE, but server says class not found

流过昼夜 提交于 2019-12-20 06:59:29
问题 I am using the Symfony3 plugin in PhpStorm. My PHP Interpreter is 7.0.18. I have PHPUnit 6.3.0 configured in PhpStorm by having the .phar file in the root directory of my project. Unit test work like a charm inside the IDE however performing any operation on the server (like bin/console server:start ) triggers the following messages: PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found in /1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php on

PHPUnit working in IDE, but server says class not found

别等时光非礼了梦想. 提交于 2019-12-20 06:55:27
问题 I am using the Symfony3 plugin in PhpStorm. My PHP Interpreter is 7.0.18. I have PHPUnit 6.3.0 configured in PhpStorm by having the .phar file in the root directory of my project. Unit test work like a charm inside the IDE however performing any operation on the server (like bin/console server:start ) triggers the following messages: PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found in /1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php on

undefined action() in phpunit

心不动则不痛 提交于 2019-12-20 05:32:32
问题 <?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshDatabase; class MemberRegTest extends TestCase { /** * A basic test example. * * @return void */ public function testExample() { $response = $this->call('GET', '/addmember'); $response = $this->action('GET', 'MemberController@addmember'); } } After testing gives me error Error: Call to undefined method Tests\Feature\MemberRegTest::action() What i do wrong?