PHPUnit complaining about missing PHPUnit_Extensions_Story_TestCase - php

Lately I've been having problems with PHPUnit, which keeps complaining about missing PHPUnit_Extensions_Story_TestCase despite the fact that the extension is installed (previous installed using pear install phpunit/PHPUnit_Story).
This only happens when I'm running a unit test that fails. So, instead of having a "normal" proper failure stack trace, I have something like this:
ECould not find PHPUnit_Extensions_Story_TestCase
#0 PHPUnit_Util_Fileloader::{closure}(PHPUnit_Extensions_Story_TestCase) called at [/Users/pedro/Code/Repositories/api-v2/src/XXX/system/Autoloader.php:40]
#1 Autoloader->autoload(PHPUnit_Extensions_Story_TestCase)
#2 spl_autoload_call(PHPUnit_Extensions_Story_TestCase)
#3 class_exists(PHPUnit_Extensions_Story_TestCase) called at [phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110]
#4 PHPUnit_Util_Blacklist->initialize() called at [phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:74]
#5 PHPUnit_Util_Blacklist->isBlacklisted(phar:///usr/bin/phpunit/php-invoker/Invoker.php) called at [phar:///usr/bin/phpunit/phpunit/Util/Filter.php:105]
#6 PHPUnit_Util_Filter::getFilteredStacktrace(PHP_Invoker_TimeoutException Object ([] => Execution aborted after 5 seconds,[] => ,[] => 0,[] => phar:///usr/bin/phpunit/php-invoker/Invoker.php,[] => 111,[] => Array ([0] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/data/adapters/MySQLiAdapter.php,[line] => 160,[function] => callback,[class] => PHP_Invoker,[type] => ->,[args] => Array ([0] => 14)),[1] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/data/adapters/MySQLiAdapter.php,[line] => 306,[function] => query,[class] => XXX\data\adapters\MySQLiAdapter,[type] => ->,[args] => Array ([0] => SELECT * FROM `users` ORDER BY RAND() LIMIT 82 )),[2] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/data/objects/Mapper.php,[line] => 138,[function] => select,[class] => XXX\data\adapters\MySQLiAdapter,[type] => ->,[args] => Array ([0] => `users`,[1] => ,[2] => RAND(),[3] => 82)),[3] => Array ([file] => /Users/pedro/Code/Repositories/api-v2/src/XXX/resources/hybrid/Users.php,[line] => 53,[function] => read,[class] => XXX\data\objects\Mapper,[type] => ->,[args] => Array ([0] => RAND(),[1] => 82)),[4] => Array ([function] => read,[class] => XXX\resources\hybrid\Users,[type] => ->,[args] => Array ([0] => XXX\data\objects\Operation Object
This goes on how don't know how many hundreds of lines more until if finally tells the actual problem:
Time: 20.35 seconds, Memory: 18.50Mb
There was 1 failure:
1) Tests\XXX\resources\hybrid\NotificationsTest::testReadNotificationsWithLimit
Failed asserting that '4567135422196220076' matches expected 4567135456555958453.
/Users/pedro/Code/Repositories/api-v2/tests/XXX/resources/hybrid/NotificationsTest.php:168
FAILURES!
Tests: 5, Assertions: 15, Failures: 1.
Generating code coverage report in Clover XML format ...
I'm running PHPUnit 4.0.10 and have installed PHPUnit_Story-1.0.2 . I understand that this is not a normal behaviour, but unfortunately I don't know how to get rid of this. Any suggestions?
P.S. - I was checking /usr/bin/phpunit file and in the autoload function, the $classes array is missing an entry with 'phpunit_extensions_story_testcase' ...but if I try to edit the file, Phar complains about invalid signature.

Your custom autoloader at /Users/pedro/Code/Repositories/api-v2/src/XXX/system/Autoloader.php is outputting that stuff instead of returning false on line 40. Without seeing the source code of said autoloader, it's impossible to say why that is happening.
PHP autoloaders are supposed to silently return false if a class cannot be loaded. This is required to allow chaining multiple autoloaders. PHPUnit uses its own autoloader for its own code which cannot run correctly due to your custom autoloader not following the spec.

I have the same problem and the only way I solved it --for now-- was downgrading to PHPUnit 3.7.32.

Had the same problem with phpunit 4.x. in combination with the Yii 1.x autoloader. Unit testing works fine, usually, but breaks as soon as I enable code coverage.
Disclaimer: The following is really ugly but it works for me:
Just add an empty class to your project so the autoloader doesn't fail.
<?php
if(!class_exists('PHPUnit_Extensions_Story_TestCase'))
{
/**
* PHPUnit_Extensions_Story_TestCase
*
* This skeleton class is added to get code coverage collection using XDebug
* and PHPUnit 4.x working again.
*/
class PHPUnit_Extensions_Story_TestCase
{
}
}

Related

PHP Soap - SOAP-ERROR: Encoding: object hasn't 'checkConnectivityRequest' property

I'm having a problem getting a particular SOAP call to work -most of them work fine, but this one is giving me a headache.
The WSDL is http://fibre.venus.ispwebhost.com/FibreClassTest/colt.wsdl, and the request I am generating is:
$result = $soap->checkConnectivity(
array('checkConnectivityRequest' =>
array(
'requestType' => 'SITE',
'requestMode' => array(
'requestId' => date("Ymdhis"),
'siteAddress' => array(
'postalZipCode' => $this->postcode,
'connectivityType' => 'COLT FIBRE',
'bandwidth' => '2M',
),
)
)
)
);
However I'm getting a SOAP error back (which I believe means it's not even passing it to the web service), so not sure if I'm mis-reading the WSDL?
Thanks!
If you search in the content of http://fibre.venus.ispwebhost.com/FibreClassTest/colt.wsdl you will notice that there is not wsdl:operation named checkConnectivityRequest. The closest i saw was checkConnectivity so, try to replace checkConnectivityRequest with checkConnectivity and let me know.
Happy coding

twice() method doesn't work in Mockery PHP

I am new to PHP Mockery Framework. I have a mock function executePrepared($arg1, $arg2, arg3) which I am calling it twice but seems to be not working and gives below error in PHPUnit command line:
Configuration read from C:\xampp\htdocs\DatabaseTesting\phpunit.xml
..←[31;1mE←[0m
Time: 47 ms, Memory: 3.25Mb
There was 1 error:
1) Test\Database\Table\TableTest::testinsertMany
Mockery\Exception\NoMatchingExpectationException: No matching handler found for
Mockery_0_Database_PGC::executePrepared(array(0=>'ClayPipe',1=>2000,2=>2100,3=>1
,4=>'2000-01-01',5=>'{"1":"1","2":6,"3":8,"4":10}',), "insert_assets", "\Databas
e\Model\Asset"). Either the method was unexpected or its arguments matched no ex
pected argument list for this method
my test function is as below:
public function testinsertMany() {
$this->PGCMock->shouldReceive('executePrepared')->twice()->withArgs(array(
[array('Clay Pipe',2000,2100,1,'2000-01-01','{"1":"1","2":6,"3":8,"4":10}'), 'insert_assets', '\Database\Model\Asset'],
[array('Main Street',1000,1100,0,'2000-02-01','{"1":"1","2":6,"3":8,"4":10}'), 'insert_assets', '\Database\Model\Asset']))
->andReturn($expectedResult1);
$data1 = array('name'=>'Clay Pipe',
'hist_cost' => 2000,
'val_cost' => 2100,
'val_method' => 1,
'service_date' => '2000-01-01',
'tags' => '{"1":"1","2":6,"3":8,"4":10}'
);
$data2 = array('name'=>'Main Street',
'hist_cost' => 1000,
'val_cost' => 1100,
'val_method' => 0,
'service_date' => '2000-02-01',
'tags' => '{"1":"1","2":6,"3":8,"4":10}'
);
$actualResult = $this->tableMock->insertMany(array($data1,$data2));
}
I don't understand what's wrong here. Is my Syntax for calling mock function twice() with passed argument wrong? Could any body please guide me here?
twice() should be used when the same call (including arguments) is expected to be executed 2 times. Looks like you want to check 2 consecutive calls, each with distinct argument.
If that is the case, this would work:
$this->PGCMock
->shouldReceive('executePrepared')
->once()
->ordered()
->withArgs([
array('Clay Pipe',2000,2100,1,'2000-01-01','{"1":"1","2":6,"3":8,"4":10}'),
'insert_assets', '\Database\Model\Asset'
])
->andReturn($result1);
$this->PGCMock
->shouldReceive('executePrepared')
->once()
->ordered()
->withArgs([
array('Main Street',1000,1100,0,'2000-02-01','{"1":"1","2":6,"3":8,"4":10}'),
'insert_assets', '\Database\Model\Asset'
])
->andReturn($result2);

php segmentation fault function call

I am getting a segmentation fault when I call a method of an object. The method is actually implemented in the base class, and I call the same method in a lot of different places in my site, but when I call it in this particular case I get a segmentation fault.
print "<p>\$picture=" . print_r($picture, true) . "</p>\n";
// apply any changes passed in parameters
if (method_exists($picture, 'postUpdate'))
print "<p>object has a postUpdate method</p>\n";
else
print "<p>object does not have a postUpdate method</p>\n";
$picture->postUpdate(true);
If I place an exit command immediately prior to calling postUpdate I see:
$picture=LegacyPicture Object ( [row:protected] => Array ( [idbr] => 0 [idir] => 20553 [idtype] => 0 [pictype] => 0 [picorder] => 0 [picname] => [picnameurl] => [idbppic] => 1 [piccaption] => [picd] => [picsd] => [picdate] => [picdesc] => [picprint] => 0 [picsoundname] => [picsoundnameurl] => [idbpsound] => 0 [used] => 0 [picpref] => 1 [filingref] => ) [changed:protected] => Array ( ) [table:Record:private] => tblBR [prime:Record:private] => idbr [needInsert:protected] => 1 )
object has a postUpdate method.
If I place an exit command in the very first line of the method postUpdate PHP gets a segmentation fault. The method postUpdate just updates the contents of the object based upon $_POST. There is no recursion. The fault happens immediately. What could go wrong in between calling the method and the very first line of code in the method that would cause a segmentation fault? Running PHP Version 5.5.9 on Apache 2.4.7.
I kept digging and found that the bug was in a routine called by the common method postUpdate which as a result of a typing error did introduce an infinite recursion. So this is the same old segmentation fault.

CakePHP SoapClient drops fields?

My app uses CakePHP (2.2.5) to get data from a SOAP server. I put logging into the SoapSource.php connector to see the XML returned and to display the array returned:
$result = $this->client->__soapCall($method, array('parameters' => $tParams));
Logger::write('SOAP Last Response', $this->client->__getLastResponse(), 3, 'transaction');
Logger::write('SOAP Last Response Object', print_r($result, TRUE), 3, 'transaction');
But what I'm seeing in the log is that two (recently-added) fields present in the XML are missing from the array, specifically, the last two before the RPList (formatted here but otherwise verbatim):
<transactionResult>
<id>test</id>
<resultCode>0</resultCode>
<ReadScheduledRecordingsRsp>
<RecordingDefinitionList>
<RecordingDefinition>
<RDId>d8c16d8f-67c6-469a-83c3-d51d8f8859a9</RDId>
<Title>The Young and the Restless</Title>
<SeriesId>4422</SeriesId>
<KeepUntil>SpaceIsNeeded</KeepUntil>
<StartPadSeconds>0</StartPadSeconds>
<EndPadSeconds>0</EndPadSeconds>
<Frequency>EveryDay</Frequency>
<KeepAtMost>0</KeepAtMost>
<Priority>23</Priority>
<ShowType>Any</ShowType>
<AirtimeDomain>SpecificTime</AirtimeDomain>
<ChannelDomain>SpecificChannel</ChannelDomain>
<RPList>
...
Followed by:
ARRAY
(
[transactionResult] => stdClass Object
(
[id] => test
[resultCode] => 0
[ReadScheduledRecordingsRsp] => stdClass Object
(
[RecordingDefinitionList] => stdClass Object
(
[RecordingDefinition] => Array
(
[0] => stdClass Object
(
[RDId] => d8c16d8f-67c6-469a-83c3-d51d8f8859a9
[Title] => The Young and the Restless
[SeriesId] => 4422
[KeepUntil] => SpaceIsNeeded
[StartPadSeconds] => 0
[EndPadSeconds] => 0
[Frequency] => EveryDay
[KeepAtMost] => 0
[Priority] => 23
[ShowType] => Any
[RPList] => stdClass Object
(
...
I'm guessing I just forgot or didn't know to do something, but I don't know what. It's just very suspicious that the two fields that don't work are the two that were just added, but I can't find any place where the fields are enumerated.
The WSDL doesn't specify any fields at all, just that there will be a bunch of data inside a transactionResult.
In the connect call, the options likewise don't specify any fields.
It all worked fine until the back-end added those two fields, and it all still works fine, except that I can't see the 2 new fields in the object.
Any ideas?
It would be nice to see the XML for RPList. What version of PHP/libxml?
Have you actually validated the XML returned by __getLastResponse()?
It sounds to me like your using WSDL mode for the client but your WSDL file lacks precision. Try using a WSDL which actually describes the data being served up by the API.
Am I understanding that the $result object when dumped lists RPList but the value is not what you expect? If so you might be able to get away with adding the SOAP_SINGLE_ELEMENT_ARRAYS option to the clients constructor: new SoapClient($wsdl, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));. That's a long shot though. Need to see WSDL and full output from __getLastResponse().
Any errors? Try wrapping the call like so:
try {
$client = new SoapClient ('http://yoursite.com?WSDL',
array("trace" => 1,
"exceptions" => true,
"cache_wsdl" => WSDL_CACHE_NONE,
"features" => SOAP_SINGLE_ELEMENT_ARRAYS)
);
$result = $client->SomeMethod($data);
} catch (SoapFault $exception) {
var_dump($exception);
} catch (Exception $exception) {
var_dump($exception);
}
Short of fixing the WSDL/XML response your workaround seems like the best solution.

phpunit data provider

I am working on PHPunit tests and so far everything is great. There is one issue, however, and it is with the following setup. Ideally I'd like to select the next value in the sequence (postgreSQL) and pass that into the function so I can validate it against the array returned from my class being tested (new row in database).
The issue is that before the array is returned from the data provider (if I echo it) it is the correct value, but during the test it comes through as blank. Is there a particular series of steps I'm missing in here in terms of what I expect or must I do this a different way?
/**
* #dataProvider testSignupProvider
*/
public function testSignup($a, $b, $c)
{
...stuff is done with $a,$b,$c
}
public function testSignupProvider()
{
$uid = fetchOne(X("SELECT currval('users_id_seq')"));
return array(
array(false, array(), $error4),
array(
'email'=>'stack#overflow.com',
'password'=>'youaintgonnagetit',
$error3
),
array(
array('id'=>$uid,'email'=>'PHPUNIT#gmail.com','username'=>'Guest'),
array('email'=>'PHPUNIT#gmail.com','password'=>'youaintgonnagetit'),
null
)
);
}
Output:
Array
(
- [id] =>
+ [id] => 2
[email] => PHPUNIT#gmail.com
[username] => Guest
)
I've gotten around this by assigning the 'id' array element to '#id' and in the function test I pull the current id in the sequence at that time.
Still will accept an answer to anyone who can tell me why this behavior occurs but hopefully this will help anyone else with this issue.

Categories