标签: phpunit

从不同目录进行 PhpUnit 测试

我已经使用 pear 在 wamp 服务器中安装了 phpunit,目录结构如下 C:\Easy-PHP\pear\PHPUnit。

PHPUnit 运行良好,我可以从全局运行它,即 c:\phpUnit

我的问题是如何从目录内运行测试?

例如:

我有要在 c:\Users\j.bloggs\workspace\assets\project-name\classes\myClass.php 中测试的类

我在 c:\Users\j.bloggs\workspace\assets\project\tests\myClassTest.php 中有测试

如何设置使用 PHPUnit 以这种方式运行测试?我看到了关于 phpunit.xml 和 bootstrap.php 的信息,我该如何实现这些?我还没有找到任何关于这一点的明确信息。

谢谢你的帮助。

php phpunit unit-testing easyphp wampserver

0
推荐指数
1
解决办法
2028
查看次数

phpunit testing with sqlite and laravel eloquent

I have a package that uses DB, and I wanted to create some tests that will run with sqlite in memory for the tests.

Now I have this base test class:

use Illuminate\Database\Capsule\Manager;

class TestCaseDb extends \PHPUnit_Framework_TestCase {
    protected $db;
    protected $tbmsg;
    public function setUp()
    {
        parent::setUp(); // //DONT CARE
        League\FactoryMuffin\Facade::getFaker()->unique($reset = true);//DONT CARE
        $this->initDb();
        $this->initTbmsg(); //DONT CARE
    }

    protected function initDb() {
        //confi gfor the sqlite
        $capsule = new Manager();
        $capsule->addConnection([
            'driver'    => 'sqlite',
            'database'  => ':memory:',
            'prefix'    => …
Run Code Online (Sandbox Code Playgroud)

php sqlite phpunit laravel eloquent

0
推荐指数
1
解决办法
3117
查看次数

PHPUnit version does not match version in Composer

I'm trying to update my phpunit version, however it doesn't seem to be working with the regular composer install.

My composer.json file is as follows:

{
    "require": {
        ...
    },
    "require-dev": {
        "phpunit/phpunit": "4.*",
        "phpunit/php-invoker": "^1.1",
        "phpunit/dbunit": "^2.0"
    }
}
Run Code Online (Sandbox Code Playgroud)

And running both composer install and update as php composer.phar install and php composer.phar update (I don't have composer installed globally which might be the issue?) I get

Loading composer repositories with package information
Installing dependencies (including require-dev) from …
Run Code Online (Sandbox Code Playgroud)

php phpunit composer-php

0
推荐指数
1
解决办法
820
查看次数

如何从 phpunit 覆盖率报告中排除 Composer 自动加载器文件(使用 netbeans/windows)

在此处输入图片说明

我的“测试项目”仅包含 Application.php 和 ApplicationTest.php,但 phpunit 还收集了有关 Composer 自动加载器文件的覆盖率信息,这是错误的。如何从覆盖率报告中排除自动加载器文件?

phpunit code-coverage

0
推荐指数
1
解决办法
513
查看次数

PhpStorm 令牌不匹配异常中的 PHPUnit 测试

我正在通过PhpStorm 内置测试环境在Laravel项目上运行单元测试。我收到令牌不匹配异常

所有配置均正确且工作正常。突然就出现了这个错误。我尝试使用终端,效果很好。我正在 Vagrant 下开发这个项目。

我可以做什么来解决这个问题?

我搜索并发现按如下方式更改 Laravel 的VerifyCsrfToken 可以解决此问题。但我也需要将其设置为默认值。 $except = ['/*']

phpunit phpstorm laravel

0
推荐指数
1
解决办法
1764
查看次数

PHP致命错误:未捕获错误:调用未定义的方法PHPUnit\Util\Configuration :: getExtensionConfiguration()

我想按照这里的说明https://laravel.com/docs/5.6/testing.在环境部分这里我做了什么.

php artisan env --env=testing
Run Code Online (Sandbox Code Playgroud)

然后跑

phpunit
Run Code Online (Sandbox Code Playgroud)

但在那之后,这条消息就出现了

PHP Fatal error:  Uncaught Error: Call to undefined method PHPUnit\Util\Configuration::getExtensionConfiguration() in /mnt/c/projects/www/janicalizdotcom/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:953
Stack trace:
#0 /mnt/c/projects/www/janicalizdotcom/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(153): PHPUnit\TextUI\TestRunner->handleConfiguration(Array)
#1 /usr/share/php/PHPUnit/TextUI/Command.php(195): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#2 /usr/share/php/PHPUnit/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#3 /usr/bin/phpunit(34): PHPUnit\TextUI\Command::main()
#4 {main}
  thrown in /mnt/c/projects/www/janicalizdotcom/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 953
Run Code Online (Sandbox Code Playgroud)

那什么意识?我该怎么办呢?

自从第一次进行laravel测试以来,我不得不提出想法

phpunit laravel-5.6

0
推荐指数
1
解决办法
1263
查看次数

Autoload file for a simple PHP unit test not working

我正在尝试熟悉 PHPUnit,我遵循了所有说明here("Getting Started with PHPUnit 7")

我复制/粘贴了这些src/Email.phptests/EmailTest.php代码源。我的问题是当我尝试运行./phpunit --bootstrap src/autoload.php tests/EmailTest. 文档说我必须创建那个 src/autoload.php,所以我遵循了提到的第一个例子here("Autoloading Classes")

<?php
// Maybe I do not need this require_once() stuff?
require_once('src/Email.php');
require_once('tests/EmailTest.php');

spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});

$obj  = new Email('bart.simpson@outlook.com');
$obj2 = new EmailTest(); 
?>
Run Code Online (Sandbox Code Playgroud)

但是当我使用上一个命令进行测试时,我收到此错误消息:

PHP Error:  Call to private Email::__construct() from context 'PHPUnit\Util\FileLoader' in /var/www/html/php_project/src/autoload.php on line 9
PHP Stack trace:
PHP   1. {main}() /var/www/html/php_project/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /var/www/html/php_project/vendor/phpunit/phpunit/phpunit:53
PHP …
Run Code Online (Sandbox Code Playgroud)

php phpunit autoload

0
推荐指数
1
解决办法
2564
查看次数

向Mockery添加接口以模拟(硬依赖性)

我需要通过重载来模拟CurrencyEnum,但这不是最终目的,因为我需要向该模拟中添加接口。这不起作用:

Mockery::mock('overload:'.CurrencyEnum::class);
Run Code Online (Sandbox Code Playgroud)

错误:(..) must be an instance of \BaseCurrency, instance of \CurrencyEnum given。我看着,但Mockery\Container::mock我不知道该怎么做。例如我要测试TestingClass::first()方法

class CurrencyEnum implements BaseCurrency
{
    /* methods */
}


class TestingClass
{
    public function first(string $currencySymbol)
    {
        $abc = 'some_string';

        return $this->second($abc, new CurrencyEnum($currencySymbol));
    }

    private function second(string $abc, BaseCurrency $currency)
    {
        /* code */
    }
}
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing mockery

0
推荐指数
1
解决办法
251
查看次数

Laravel:assertDatabaseHas - 意外失败

我不明白为什么这个数据库测试失败。我知道我没有在 created_at 和 updated_at 列上断言,但是三列(id、user_id、thing_id)应该足够了,我确信我之前只测试了一些列,并且它工作了!

我错过了什么?

    Failed asserting that a row in the table [thing_history] matches the attributes [
            {
                "id": 1,
                "user_id": 1,
                "thing_id": 1
            },
            {
                "id": 2,
                "user_id": 1,
                "thing_id": 2
            },
            {
                "id": 3,
                "user_id": 1,
                "thing_id": 3
            }
        ].

        Found: [
            {
                "id": "1",
                "user_id": "1",
                "thing_id": "1",
                "created_at": "2019-02-01 21:18:17",
                "updated_at": "2019-02-01 21:18:17"
            },
            {
                "id": "2",
                "user_id": "1",
                "thing_id": "2",
                "created_at": "2019-02-01 21:18:17",
                "updated_at": "2019-02-01 21:18:17"
            },
            {
                "id": "3",
                "user_id": "1",
                "thing_id": …
Run Code Online (Sandbox Code Playgroud)

testing phpunit laravel

0
推荐指数
1
解决办法
3613
查看次数

嵌套数组上的 Laravel AssertJsonCount

如何assertJsonCount使用带索引的嵌套数组进行调用?

在我的测试中,返回以下 JSON:

[[{"sku":"P09250"},{"sku":"P03293"}]]
Run Code Online (Sandbox Code Playgroud)

但是尝试使用会assertJsonCount返回以下错误:

$response->assertJsonCount(2);

// Failed asserting that actual size 1 matches expected size 2.
Run Code Online (Sandbox Code Playgroud)

testing phpunit json assert laravel-5

0
推荐指数
1
解决办法
3345
查看次数