phpunit

How to unit test the methods of a class whose constructor take some arguments?

江枫思渺然 提交于 2020-05-26 01:22:10
问题 I have a class of form something like this: class A{ public function __constructor(classB b , classC c){ // } public function getSum(var1, var2){ return var1+var2; } } My test case class is something like this: use A; class ATest extends PHPUnit_Framework_TestCase{ public function testGetSum{ $a = new A(); $this->assertEquals(3, $a->getSum(1,2)); } } However when I run the phpunit, it throws some error like: Missing argument 1 for \..\::__construct(), called in /../A.php on line 5 Even if I

TDD: best practices mocking stacks of objects

自作多情 提交于 2020-05-16 19:09:51
问题 I'm trying to get familiar with unit testing in PHP with a small API in Lumen. Writing the first few tests was pretty nice with the help of some tutorials but now I encountered a point where I have to mock/ stub a dependency. My controller depends on a specific custom interface type hinted in the constructor. Of course, I defined this interface/implementation-binding within a ServiceProvider. public function __construct(CustomValidatorContract $validator) { // App\Contracts

how to run php unit multiple times and concatenate the coverage report?

旧城冷巷雨未停 提交于 2020-05-09 02:25:07
问题 My tested code is full of final static classes. and while we can't refactor it for better tests, i have a intermediate solution that runs several small tests on it's own process. and all works fine. but i get no coverage report as one overwrite the other. I'm currently generating the report in clover, but i am very open to other reports. my tests only work when phpunit is run as: /home/y/bin/phpunit --coverage-html clover --coverage-clover clover/report.xml --include-path src/ tests/aTest.php

PHP-不同Str 拼接方法性能对比 参考自https://www.cnblogs.com/xiaoerli520/p/9624309.html

徘徊边缘 提交于 2020-04-30 16:32:38
问题 在PHP中,有多种字符串拼接的方式可供选择,共有: 1 . , .= , sprintf, vprintf, join, implode 那么,那种才是最快的,或者那种才是最适合业务使用的,需要进一步探究。 用到的工具 PHP7.1.16 PHP5.4 VLD XDebug phpunit4 以及自己写的一个Benchmark工具。 PHP54环境 PHPUnit测试结果 使用以下代码,分别测试了上面的几种字符串拼接方式(拼接方式无法对变量赋值,故用处不大,没有测,join和implode是相等的,仅仅测试了其中一个) 测试条件:2C-4T 8G 拼接5W次,重复10次取平均值。 测试代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 <?php /** *

PHP-不同Str 拼接方法性能对比

不打扰是莪最后的温柔 提交于 2020-04-30 15:07:35
问题 在PHP中,有多种字符串拼接的方式可供选择,共有: 1 . , .= , sprintf, vprintf, join, implode 那么,那种才是最快的,或者那种才是最适合业务使用的,需要进一步探究。 用到的工具 PHP7.1.16 PHP5.4 VLD XDebug phpunit4 以及自己写的一个Benchmark工具。 PHP54环境 PHPUnit测试结果 使用以下代码,分别测试了上面的几种字符串拼接方式(拼接方式无法对变量赋值,故用处不大,没有测,join和implode是相等的,仅仅测试了其中一个) 测试条件:2C-4T 8G 拼接5W次,重复10次取平均值。 测试代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 <?php /** *

基于 Redis 的订阅与发布

守給你的承諾、 提交于 2020-04-21 14:26:36
Github 仓库 demo-redis-subscribe 创建项目 $ composer create hyperf/biz-skeleton demo-redis-subscribe dev-master Installing hyperf/biz-skeleton (dev-master 1eaa35a957cf704a5c9959c68e426a614c7598a2) - Installing hyperf/biz-skeleton (dev-master 1eaa35a): Cloning 1eaa35a957 from cache Created project in demo-redis-subscribe > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 133 installs, 0 updates, 0 removals - Installing ocramius/package-versions (1.4.0): Loading from

lumen单元测试

喜欢而已 提交于 2020-04-18 13:35:04
phpunit --filter testInfo tests/UserTest.php UserTest.php <?php use Laravel\Lumen\Testing\DatabaseMigrations; use Laravel\Lumen\Testing\DatabaseTransactions; class UserTest extends TestCase { public function testInfo() { dd(4444444); $swoole = app('swoole'); var_dump($swoole); } }    来源: oschina 链接: https://my.oschina.net/u/4321566/blog/3274089

Json Assert Fails Laravel 5.5

痴心易碎 提交于 2020-04-17 22:12:32
问题 I am making a flash cards app with laravel 5.5 So I am trying to make the first tests but I can't make it pass. Failed asserting that an array has the subset Array &0 ( 'data' => Array &1 ( 'id' => 2020 ) ). --- Expected +++ Actual @@ @@ - [data] => Array - ( - [id] => 2020 - ) - /Users/marcosantana/devel/cards/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:290 /Users/marcosantana/devel/cards/tests/Unit/CardTest.php:26 FAILURES! Tests: 1, Assertions: 1, Failures:

Json Assert Fails Laravel 5.5

血红的双手。 提交于 2020-04-17 22:11:15
问题 I am making a flash cards app with laravel 5.5 So I am trying to make the first tests but I can't make it pass. Failed asserting that an array has the subset Array &0 ( 'data' => Array &1 ( 'id' => 2020 ) ). --- Expected +++ Actual @@ @@ - [data] => Array - ( - [id] => 2020 - ) - /Users/marcosantana/devel/cards/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:290 /Users/marcosantana/devel/cards/tests/Unit/CardTest.php:26 FAILURES! Tests: 1, Assertions: 1, Failures:

PHPUnit: How to test a method which calls another function declared in different file

爱⌒轻易说出口 提交于 2020-04-15 10:53:28
问题 I'm trying to test a method using PHPUnit, where it calls another function ( standalone function, without class ), which resides in different file which does a some pretty good calculation and returns a object. This is my actual main code: class CreateRecords { public function createEntities($details) { if (trim($details['username']) == "") { $this->result = "Username is empty."; } else { $this->result = create_record($Details['username']); } return $this->result; } } This create_record