Currently I'm trying to implement the Doctrine CouchDB Bundle in a Silex Application. At one point the complete site ends in a 500/internal server error in my local dev stack. Setting breakpoints and debugging them with XDebug and PHPStorm hasn't brought me to any result so far. Apache Error logs are empty, PHP error logs as well and error_reporting(-1); still doesn't give any output. Probably the problem is the reflection class usage in there.
Everything works well, until I try to use CouchDB Annotations from
use Doctrine\ODM\CouchDB\Mapping\Annotations as CouchDB;
and use them in my Document
/** #CouchDB\Document */
class Station
{
/**
* #Index
* #Id
*/
private $id;
If I remove the CouchDB\ above, everything works. But if I remove it, and use #Id(strategy="ASSIGNED"), I run into the exact same problem.
I tried to register the Annotations in several ways without luck. #Ocramius suggested in chat that I should simply override the Autoloader, which worked well with getting beyond some other problems, but not for that case (just adding it here in case someone else needs it).
AnnotationRegistry::registerLoader( function( $className ) {
return class_exists( $className );
} );
Try to use
/**
* #CouchDB\Index
* #CouchDB\Id
*/
instead of
/**
* #Index
* #Id
*/
You can also solve this by adding this line before you run your Silex Application (probably in index.php).
AnnotationRegistry::registerLoader('class_exists');
Related
I have a symfony 3.4 project in PhpStorm 2020.2. I import the following annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
and use them, for example here:
/** #Route("/feedback/delete/{id}", name="feedbackDelete") #Method("DELETE") */
and
/** #Route("/dashboard", name="dashboard") #Template() */
Now PhpStorm tells me Import 'Sensio\Bundle\FrameworkExtraBundle\Configuration\Method' is never used - same for Template. That is not true, but why does PhpStorm not recognize it?
I use the plugins PHP Annotations 7.1.3 and Symfony Support 0.21.202.
It's annoying because it always shows up in code analyses and I can't auto-optimize imports, because it breaks the code.
I thought, why bothering to ask - symfony 3.4 is old and I will probably soon migrate to symfony 5.X. But migration is a headache and since I recently talked with someone from a big symfony project where they still use 2.*, I thought there might actually be more people with this problem.
After experimenting a bit, I found the problem:
The PhpStorm plugin PHP Annotations does recognize the annotation, if it is starting in a new line of the PhpDoc. So while #Template is not recognized as used here:
/** #Route("/dashboard", name="dashboard") #Template() */
it works, if I change it to
/**
* #Route("/dashboard", name="dashboard")
* #Template()
*/
or even this is enough:
/** #Route("/dashboard", name="dashboard")
* #Template() */
I don't really like that since I like to keep my line count low and I don't see any advantage of putting this small annotation in a new line, but at least now I have a work-around.
I also opened an issue for this which can be found here: https://github.com/Haehnchen/idea-php-annotation-plugin/issues/211
Using php session in laravel 5 seems impossible to me. But there is no limit to knowledge.
I got a project from somebody in which php session was used in a laravel project. The project is so huge that converting the php sessions to laravel session is a huge task.
But it seems that the php session supports to work on localhost i.e. wamp and the project seems bug free. But deploying on the server its a mess. The server is a linux server. i tried to replicate the setttings to wamp. But can't get it working.
Is there any minor chance of making the application working without going through the whole project.
Got a fix to it.
The solution was
Since the project was to large to change the whole code so i added a small piece of code in the AppServiceProvider
<?php
namespace App\Providers;
session_start();
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
$this->composer();
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
}
public function composer(){
view()->share($_SESSION);
}
}
Which defined as a variable in the whole Laravel project as well as session variables to where ever required.
Even though this is not the right way to use session but it helps to fix the issue.
I've recently set up PHPUnit in PHPStorm via Composer.
I'm trying to test some functionality that requires me to bootstrap Processwire (a CMS).
I keep constantly getting the message "You cannot serialize or unserialize PDO instances" despite applying the conditions below which I researched to be the correct way of fixing this issue.
* #backupGlobals disabled
* #backupStaticAttributes disabled
* #runTestsInSeparateProcesses
* #runInSeparateProcess
* #preserveGlobalState disabled
Is there anything else I have missed or need to do to get this working?
These are the resources I have referenced so far.
https://phpunit.de/manual/current/en/phpunit-book.html#appendixes.annotations.preserveGlobalState
http://edmondscommerce.github.io/php/phpunit-and-pdoexception-solution.html
I've seen this article that flagged my article as a duplicate but I don't believe it to be the same :
PDOException: You cannot serialize or unserialize PDO instances
The test in that article has direct references to the PDO object whereas I'm just trying to get my tests to run with a bootstrap reference to Processwire.
This is my test I'm trying to run :
namespace Test;
include_once(__DIR__."/../../../../index.php"); //Bootstrap to Processwire CMS
class ImageTest extends \PHPUnit_Framework_TestCase {
/**
* #backupGlobals disabled
* #backupStaticAttributes disabled
* #runTestsInSeparateProcesses
* #runInSeparateProcess
* #preserveGlobalState disabled
*/
protected function setUp()
{
//$this->testpages = wire(pages)->find("template=fingergames|template=songs|template=poems");
}
public function testImageEmptyLinks()
{
//$testpages = wire(pages)->find("template=fingergames|template=songs|template=poems");
$blanks = wire(pages)->find("image=''");
$this->assertEquals($blanks->count(),0);
}
public function testImageMismatchedLinks()
{
//$this->assertTrue(true);
$this->assertEquals(0,0);
}
public function testImageMissingSiblings()
{
$this->assertEquals(0,0);
}
protected function tearDown()
{
}
}
I finally figured it out! For whatever reason, setting the test environment variables in the test was having no effect.
By creating a phpunit.xml configuration, defining the test parameters and creating a reference to it in Phpstorm I was finally able to run the test.
For reference, this was the contents of my phpunit.xml
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
processIsolation="false">
</phpunit>
I don't think it matters where the file is placed but I placed it in the test folder where my tests resides.
And I had to reference it in PHPStorm by going through the menu (Language & Framework -> PHP -> PHPUnit) and in the Custom Autoloader section, selecting the default configuration file and pointing it to the phpxml file. If you're using a different method, then go to that menu and set the default configuration there.
Hope this helps somebody out there, as there isn't much information relating to PHPUnit & PHPStorm in conjunction.
I have a unit tested application which we have updated from symfony 2.3 to 2.6. We followed all upgrading docs and had to change only some minor stuff.
Everything is working perfectly, except for the PHPUnit tests.
We have 2 seperate runs, one for only testing the entity classes, which is fired on a pre-commit hook. and a second one which runs the full suite, with database setups and the whole nine yards.
Now since the upgrade to 2.6, the PHPUnit_Framework_Error thrown in the unit tests have been replaced by Symfony's Symfony\Component\Debug\Exception\ContextErrorException, this failing all tests like this:
/**
* #dataProvider objectTestDataProvider
* #expectedException \PHPUnit_Framework_Error
*/
public function testCanNotSetClientToArbitraryValue($value)
Now I do not want to change this into the new Exception since running the entity-only test suite does not depend on symfony components, thus symfony is not loaded, thus the errors are the regular PHPUnit_Framework_Error so changing it makes these tests fail.
In other words, when I run one test class it works, once a symfony dependent test is run, it fails:
# runs perfectly
phpunit -c app/phpunit.xml --debug src/My/Bundle/Tests/Entity
# fails when reaching the tests that ran perfectly in previous command
phpunit -c app/phpunit.xml --debug
This new ErrorHandler seems undocumented, I couldnt find much about it in google except for the pull request and this small article
I've tried:
setting the SYMFONY_DEBUG=0 environment variable, but this doesnt seem to make any difference.
adding the debug.error_handler.throw_at: 0 parameter to my test_config.yml
edit:
On request by #cerad I've tried to isolate the tests to try and reproduce the code with as little as possible, Ive managed to reproduce with 4 tests:
class MyControllerTest extends WebTestCase
{
public function testRoutesLoaded_1()
{
$client = self::createClient();
/** #var Router $router */
$router = $client->getKernel()->getContainer()->get('router');
$this->assertEquals('/menu', $router->generate('front_menu'));
}
/**
* #expectedException \PHPUnit_Framework_Error
*/
public function testCreateOrder_1()
{
new Order(); // required parameter missing
}
public function testRoutesLoaded_2()
{
$client = $this->createNewFrontClient();
/** #var Router $router */
$router = $client->getKernel()->getContainer()->get('router');
$this->assertEquals('/menu', $router->generate('front_menu'));
}
/**
* #expectedException \PHPUnit_Framework_Error
*/
public function testCreateOrder_2()
{
new Order(); // required parameter missing
}
}
As you can see, I just run the same exact test 2 times, but still the last one results in an error:
MyControllerTest::testCreateOrder_2
Failed asserting that exception of type "Symfony\Component\Debug\Exception\ContextErrorException" matches expected exception "\PHPUnit_Framework_Error"
Since I did not get any replies here, I posted an issue on Symfony's github and they confirmed this was incorrect behavior.
The issue was resolved and is merged in 2.6-dev.
I am implementing Swagger-PHP for an API we've built.
Here is a brief recap:
Language: PHP5.3
Framework: FuelPHP 1.5.3
Environment: Local (served with Nginx)
Now I have an API method defined as follow:
/**
* #SWG\Api(
* path="/site/list",
* description="Get sites list",
* #SWG\Operation(...,
* #SWG\Parameter(...),
* #SWG\ResponseMessage(...),
* #SWG\ResponseMessage(...)
* )
* )
*/
public function action_run()
{
//doing stuff
}
I now try the following (from elsewhere in my application) to generate the JSON:
$swagger = new Swagger\Swagger('my/root/dir');
$swagger->getResource('/site/list', array('output' => 'json'));
And that first line here (when instanciating my Swagger class) is throwing me an error:
ErrorException [ User Warning ]: [Semantical Error] The class
"package" is not annotated with #Annotation. Are you sure this class
can be used as annotation? If so, then you need to add #Annotation to
the class doc comment of "package". If it is indeed no annotation,
then you need to add #IgnoreAnnotation("package") to the class doc
comment of class #Swagger\Annotations\Api.
Adding the #IgnoreAnnotation("package") is actually not helping.
I notice the error disappears if I remove the #package from here:
https://github.com/zircote/swagger-php/blob/master/library/Swagger/Annotations/Api.php#L28
But that's not a solution.
I'm guessing this is mainly Doctrine-related but I can't seem to figure it out.
Thanks for any tips or ideas on that matter.
Because FuelPHP has a Package class (in fuel/core/package.php), which isn’t an #Annotation the DocParser generates this warning.
Swagger-PHP uses the $docParser->setIgnoreNotImportedAnnotations(true) setting, which should prevent warnings like these.
I've reported the issue and fixed the problem but sadly the patch was rejected
Report the issue (again) to doctrine, the more people complain the faster it gets fixed 😉
As a workaround replace your DocParser.php with this version