将 PHPSpec 与数组一起使用


Using PHPSpec with array?

我一直开始使用PHPSpec 2,并且喜欢Mockery,但是遇到了一个我无法弄清楚的问题。

我有一个由静态函数返回的数组,我想验证这个数组。 确保所需的所有钥匙都在那里,等等。

我试过了:

$systems = CacheFactory::getCacheSystems();
$systems->shouldBeArray();

以及:

$systems = CacheFactory::getCacheSystems();
$this->spec($systems)->shouldBeArray();

但两者都没有奏效。 第一个原因很明显,错误地说$systems不是一个对象。 第二个错误是说我无法序列化闭包。 数组中有闭包(它是一个配置数组),但我什至尝试过滤掉它们,但无济于事。

数组示例:

array(
'someCache' => array(
    'cache' => 'SomeCacheSystem',
    'checks' => function () { return isCacheActivated(); }
),

目前在 PHPSpec 2 中可以做到这一点吗? 我只是错过了一些愚蠢的东西,我对框架很陌生。

我假设CacheFactory是规范下的主题:

<?php
namespace spec;
use PhpSpec'ObjectBehavior;
use Prophecy'Argument;
class CacheFactorySpec extends ObjectBehavior
{
    function it_has_all_the_keys_needed()
    {
        $this::getCacheSystems()->shouldBeArray();
    }
}