我将生产代码与测试代码分开保存在两个单独的文件中package.这可能有点阴暗,但它一直运作良好,因为我避免了导出和导入子程序的麻烦.
我遇到了问题 constant
#! /usr/bin/perl
use strict;
use warnings;
package A;
1;
use constant WORLD => "WORLD\n";
sub helloWorld {
print STDERR "Hello, World\n";
}
sub helloAll {
print STDERR "Hello, All\n";
}
Run Code Online (Sandbox Code Playgroud)
use strict;
use warnings;
package A;
use lib '.';
require 'example.pl';
helloWorld();
helloAll();
print "Hello, ", A->WORLD;
Run Code Online (Sandbox Code Playgroud)
./test.pl
Hello, World
Hello, All
Hello, WORLD
Run Code Online (Sandbox Code Playgroud)
这一切看起来都不错,但是如果我尝试将常量引用为WORLD或 A::WORLD代替A->WORLD我得到错误.
在./test.pl第13行使用"严格的子"时,不允许使用Bareword"A :: WORLD".
我想理解为什么,因为常量本质上是子程序,其余的子程序工作正常.
我在Homestead-7上使用Laravel 5.5,phpunit 6.5.5(我认为)。
我正在尝试本教程:https : //laravel-news.com/your-first-laravel-application(这应该告诉您很多我在框架方面的经验)
测试失败(由于TokenMismatchException),尽管我尝试了许多将其APP_ENV设置为的方法local,但我设法找出了设置为该变量的根本原因testing。
最后,让我克服了这个问题的是设置变量,如下所示:
APP_ENV=testing vendor/bin/phpunit
Run Code Online (Sandbox Code Playgroud)
然后,测试成功完成。
我的问题是,我在做什么错?上述破解显然不是最好的方法。必须有一种正确执行此操作的方法。
更新资料
内容phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
Run Code Online (Sandbox Code Playgroud)
预先感谢您的宝贵时间。