<?php namespace Kahlan\Spec\Suite\Plugin\Call; use Kahlan\Plugin\Call\Calls; describe("Calls", function () { beforeEach(function () { Calls::reset(); }); describe("::log()", function () { it("logs a dynamic call", function () { Calls::log('my\\name\\space\\Class', ['name' => 'methodName']); $logs = Calls::logs(); expect($logs[0][0])->toEqual(['class' => 'my\\name\\space\\Class', 'name' => 'methodName', 'instance' => null, 'static' => false, 'method' => null]); }); it("logs a static call", function () { Calls::log('my\\name\\space\\Class', ['name' => '::methodName']); $logs = Calls::logs(); expect($logs[0][0])->toEqual(['class' => 'my\\name\\space\\Class', 'name' => 'methodName', 'instance' => null, 'static' => true, 'method' => null]); }); }); describe("::lastFindIndex()", function () { it("gets/sets the last find index", function () { $index = Calls::lastFindIndex(100); expect($index)->toBe(100); $index = Calls::lastFindIndex(); expect($index)->toBe(100); }); }); });
/** * Build the description of the runned `::match()` call. * * @param mixed $startIndex The startIndex in calls log. */ public function _buildDescription($startIndex = 0) { $times = $this->times(); $report = $this->_report; $reference = $report['message']->reference(); $expected = $report['message']->name(); $with = $report['message']->args(); $expectedTimes = $times ? ' the expected times' : ''; $expectedParameters = $with ? ' with expected parameters' : ''; $this->_description['description'] = "receive the expected method{$expectedParameters}{$expectedTimes}."; $calledTimes = count($report['args']); if (!$calledTimes) { $logged = []; foreach (Calls::logs($reference, $startIndex) as $log) { $logged[] = $log['static'] ? '::' . $log['name'] : $log['name']; } $this->_description['data']['actual received calls'] = $logged; } elseif ($calledTimes) { $this->_description['data']['actual received'] = $expected; $this->_description['data']['actual received times'] = $calledTimes; if ($with !== null) { $this->_description['data']['actual received parameters list'] = $report['args']; } } $this->_description['data']['expected to receive'] = $expected; if ($with !== null) { $this->_description['data']['expected parameters'] = $with; } if ($times) { $this->_description['data']['expected received times'] = $times; } }