symfony2 autoload.php executes on my computer, but not on remote - symfony

this is my app/autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale /Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale /Resources/stubs');
$loader->add('Stof', __DIR__.'/../vendor/bundles');
$loader->add('Gedmo', __DIR__.'/../vendor/gedmo-doctrine-extensions/lib');
$loader->add('Zend\\Search' , __DIR__.'/../src/EWZ/zends');
$loader->add('EWZ', __DIR__.'/../src/EWZ');
}
the problem is, it executes the condition on my computer (loads the classes), but not on the other computers that download it through git. when i put die in the condition, it stops for me, but not for other computers.
can anyone tell me what does the condition do? as i've been failing miserably for last two hours in resolwing the problem. thx

"The condition will be entered if the intl extension doesn't exist for the current version of PHP. It sounds as though your remote servers do have it installed, but you don't locally." RobMasters

Related

Sudden syntax error after deployment

I have a working symfony project. I have it on a private bitbucked repository and locally the website works without an issue.
Today I tried to deploy the project onto an external server linuxpl.com.
Steps taken include:
Istalling composer
Adding the mysql database
Running git clone to get the data into a proper location
Running composer install on the folder to install everything and connect to the db
Cleared the cache
Set the project root as ....domain/project_name/web
However after completing all these steps, when running the website with regular server:run I'm getting this odd error:
Parse error: syntax error, unexpected '.' in /home/spirifer/domains/surowcewobiektywie.pl/konkurs/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1571
Not sure if this is of any importance but the mentioned code partion looks like this in my local files:
// Some objects throw exceptions when they have __call, and the method we try
// to call is not supported. If ignoreStrictCheck is true, we should return null.
try {
$ret = $object->$method(...$arguments);
} catch (BadMethodCallException $e) {
if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) {
return;
}
throw $e;
}
The local version does not differ from the one on the server.
My local machine has PHP 7.0.9 and the remove server has PHP 7.0.14
How could I fix this issue?
PHP 5.6 adds Variadic functions, with "...". However, Twig v1.x only required the use of PHP 5.2.7 or above.
If you didn't explicitly update to Twig 2.0, it's very possible you have used the 'death star' version constraint in the composer file - '*'. which allows uncontrolled version updates to the latest version. If this is the case, you will need to either update your version of PHP, or at least require just a previous version of Twig/twig, "^1.32" would be the latest in the version 1 series of Twig.

working dev environment symfony2.3

I'm working with a project symfony version 2.3.6 specifically. The problem is that I make changes in the code but the change is not reflected on the page until the page charge many times. I'm in dev environment. is as if not compile the code every time I load the page. Are not you supposed to be in dev environment should always be compiled? a greeting
Thanks four your answer. I use MAMP and php 5.5.3 and no select cache.
the app_dev is:
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
i comment the line //$kernel->loadClassCache(); but the problem no solve.
Symfony caches everything by default, especially Twig. And it's tedious, I know.
Looking at the manual (http://symfony.com/doc/current/book/templating.html) it says:
If you add a template in a new location, you may need to clear your
cache (php app/console cache:clear), even if you are in debug mode.
And so, you need to clear the cache. But attention deleting all, because the user sessions are stored in /cache/dev/sessions. That's another strong limitation: Symfony2 requires a writable filesystem.
There is a radical solution, but your app could get really slow, also in dev mode:
twig:
cache: false
In your config.yml

Why Can't PHPUnit UnitTest My Wordpress Website

I have been researching this issue for days and although many people ask this question I never found a clear and concise answer.
I am running:
PHP Unit: Version 3.7.21
WordPress: Version 3.5.1
OS: Ubuntu 11.10
MySQL: Version 5.1.69-0ubuntu0.11.10.1
PHP: Version 5.3.6-13ubuntu3.10
Long story short, I have the basic wordPress core downloaded into a directory on my computer. I have successfully downloaded and installed pear and phpunit. I tested phpunit by writing basic tests on simple php files which worked fine. My issue is when I run phpunit on a wordpress site (which I have not changed the core WP files of).
I get the error:
"PHP Fatal error: Call to a member function main() on a non-member
object in /< root_directory>/functions.php on line 779".
This error corresponds to this code-segment:
function wp( $query_vars = '' ) {
global $wp, $wp_query, $wp_the_query;
$wp->main( $query_vars ); // Line 779
if ( !isset($wp_the_query) )
$wp_the_query = $wp_query;
}
After some intense internet crawling I found many people had errors on this exact line so I know there is some general thing like an environment setting or our setup process that gave us all this error.
Some solutions I have read and tried that did not work for me:
Change the required file in your "index.php" file.
Place a require of "load.php" above the head in your "index.php" file.
Re-install WordPress
Change boot-strap and phpunit environments.
I have been a web-developer for 5 years but I have never used WordPress for one of my clients before. Once I can get this set up writing the unit tests will be easy; but I have no idea what is causing this issue. Any links to guides/tutorials or clear explanations would be greatly appreciated. Thank you for your time.
There is a WordPress test suite, which your question suggests you might have missed:
http://make.wordpress.org/core/handbook/automated-testing/
Keep in mind, with that being highlighted, that WP was not designed in such a way that it or anything related to it can or is supposed to be tested. The modus operandi has, for years, been to commit code with no tests at all. It's admittedly improving over the years, albeit at a slow pace.
Related questions:
What are the best practices of custom application Wordpress development?
WordPress Plugin: How do I avoid "tight coupling"?

Why does Symfony2 set the error_reporting?

I've been trying to remove the E_NOTICE and E_STRICT error levels to avoid this error:
Runtime Notice: Only variables should be passed by reference
I tried modifying php.ini but didn't work, error_reporting always is -1. Then I tried setting it dynamically in the current action, and worked fine. Then I also tried the same in the first line in app_dev.php and didn't work. Which means Symfony2 is setting it dynamically somewhere.
What should I do?
EDIT
For those who are not familiar with the error:
$user = $this->('security.context')->getToken()->getUser();
$first = reset($user->getRoles()); // error
$roles = $user->getRoles();
$first = reset($roles); // works fine
Whilst the notice is not 'retarded', this is a reasonable question in other contexts so: this is set in the Kernel instance, instantiated in app_dev.php (or app.php).
The second parameter to the construct is a boolean debug flag, and if true then error_reporting is set to -1 and display_errors to 1, otherwise default and 0 respectively.
$kernel = new AppKernel('dev', false);
symfony documentation
Hope this helps.
I got the same error in the following scenario i.e.
Scenario:
I lost the development environment for my existing LIVE project. But I got the whole code from GIT repo and then installed the symfony 2.4.2 (same version as on LIVE site) in my new development environment. Then I found that the web-application pages working on the LIVE site are broken in my new DEV environment.
Solution:
I spent quit a lot time to understand why the problem is then I found that i.e.
When I installed symfony 2.4.2 in my development environment using composer.phar then it created a new web/app_dev.php file in my development environment and it has the following entry to turn it off i.e.
Debug::enable();
Just comment the above line then the php notices will be off and then all the pages that were giving me notices are fixed.
I hope this will be helpful for someone having the same problem like me. Good Luck!
Cheers.
PS: But I will recommend to enable the above line in your new development projects so that you can see the PHP notices and then remove them during development.

PHPUnit - does nothing, no errors, no output

Sorry for another 'phpunit doesn't work' question. It used to work for years now. Today I reinstalled PEAR and phpunit for reasons not connected to this problem. Now when I run phpunit as I usually did. Nothing happens. The cli just shows me a new line, no output whatsoever.
Has anyone encountered this problem or has an idea what could have caused it.
PHPUnit Version: 3.5.15
PEAR Version: 1.9.4
PHP Version: 5.3.8
Windows 7
I'm on OSX and MAMP. To get error messages I had to adjust the following entries in php.ini:
display_errors = On
display_startup_errors = On
Please not that this has to go into /Applications/MAMP/bin/php/php5.3.6/conf/php.ini .
For future reference, for those who are facing any problem with PHPUnit, and PHPUnit is failing silently, just add this three lines inside phpunit.xml:
<phpunit ....... >
...
...
<php>
<ini name="display_errors" value="true"/>
</php>
</phpunit>
After that run the tests again, and now you can see why PHPUnit is failing,
AND ... ENJOY UNIT TESTING :)
I know the orignal poster's question is already answered, but just for any people searching in the future: one thing that can cause PHPUnit to fail silently (i.e. it just stops running tests without telling you why) is that it has an error handler that it set up before each test run, which is intended to capture errors and display them at the end of the test run. The problem is that certain errors halt execution of the whole test run.
What I generally do when this happens, as a first step, is reset the error handler to something that will immediately output the error message. In my base test class I have a method called setVerboseErrorHandler, which I'll call at the top of the test (or in setUp) when this happens. The below requires php 5.3 or higher (due to the closure), so if you're on 5.2 or lower you can make it a regular function.
protected function setVerboseErrorHandler()
{
$handler = function($errorNumber, $errorString, $errorFile, $errorLine) {
echo "
ERROR INFO
Message: $errorString
File: $errorFile
Line: $errorLine
";
};
set_error_handler($handler);
}
Create the simplest test class you can without a bootstrap.php or phpunit.xml to first verify that your new installation works. PHPUnit will stop without any message if it cannot instantiate all of the test cases--one for each test method and data provider--before running any tests.
You have already figured out how to get it to work, but my solution was a little different.
First thing you can do is check the exit status. If it's not 0, then PHP exited and because of the INI configuration settings set, none of the PHP error messages were outputted. What I did was to enable the "display_errors" INI setting, and set "error_reporting" to E_ALL. I was then able to identify errors such as PHP not being able to parse a certain script. Once I fixed that, PHPUnit ran properly.
I managed to spectacularly paint myself in a corner with a custom "fatal error handler" that in certain rare conditions turned out to output nothing. Those conditions, in accordance with Murphy's Law, materialized once I had forgotten the handler was in place.
Since it wasn't really a "PHPunit problem", none of the other answers helped [although #David's problem was at the bottom the same thing], even though the symptoms were the same - phpunit terminating with no output, no errors, no log and no clue.
In the end I had to resort to a step-by-step tracing of the whole test suite by adding this in the bootstrap code:
register_shutdown_function(function() {
foreach ($GLOBALS['lastStack'] as $i => $frame) {
print "{$i}. {$frame['file']} +{$frame['line']} in function {$frame['function']}\n";
}
});
register_tick_function(function() {
$GLOBALS['lastStack'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 8);
});
declare(ticks=1);
If anyone ever manages to do worse than this, and somehow block stdout as well, this modification should work:
register_shutdown_function(function() {
$fp = fopen("/tmp/path-to-debugfile.txt", "w");
foreach ($GLOBALS['lastStack'] as $i => $frame) {
fwrite($fp, "{$i}. {$frame['file']} +{$frame['line']} in function {$frame['function']}\n");
}
fclose($fp);
});
an old thread this one, but one I stumbled across when having the same problem.
I had the same problem, nothing being returned to console including print, print_r, echo etc.
solved it by using --stderr as a test-runner option.
Check that you haven't written any logic into your code that just dies, with no output. For example,
<?php
if (!array_key_exists('SERVER_NAME', $_SERVER)) {
die();
}
This was exactly my case; I'd made some assumptions about the environment which were correct when running the code via Apache, but weren't fulfilled when running from CLI and the code did not echo any output.
PHPUnit tried to include the bootstrap file before giving the usual init output, but died during the bootstrapping proccess, hence exiting with status 0 and no output.
If when you run from command line a recent version of phpunit like this
> php phpunit
or
> ./phpunit
or
> php ./phpunit.phar
or
> ./phpunit.phar
And you immediatly return to the prompt with no messages, this is probably due to a "suhosin secutiry" setup.
phpunit is now a "phar" package including all libraries. To be able to run such file when php has the suhosin security module enabled, you must first set this
suhosin.executor.include.whitelist = phar
into you php.ini file (for example, with debian/ubuntu, you may have to edit file /etc/php5/conf.d/suhosin.ini
i tried everything here, but nothing worked until i tried phpunit --no-configuration simpletest.php. that finally gave me some output, which implies that my phpunit.xml.dist file is broken. (i'll come back and update this once i debug it.)
the contents of simpletest.php are below, but any test file should work.
<?php
use PHPUnit\Framework\TestCase;
final class FooTest extends TestCase
{
public function testFoo()
{
$this->assertEquals('x', 'y');
}
}
Check if the phpunit you're running and the one you installed are the same:
$ pear list phpunit/phpunit
...
script /path/to/phpunit
...
Try to execute exactly that phpunit with the full path.
Then check your PATH variable and see if the correct directory is in it. If not, fix that.
If that does not help, use write something into the phpunit executable, e.g. "echo 123;" and run phpunit. Check if you see that.
For me the conflict was with Xdebug's directive
xdebug.remote_enable=1
If you are using composer, check to make sure your included PHP files are not ending the code executions. The same goes for when you included certain PHP files explicitly.
In my case, I was working on a WordPress plugin and one of the PHP files I included directly in composer.json (which I don't want to load through PSR-4 because WordPress's coding standards don't support it yet) had this code on top;
if (!defined('ABSPATH')) {
exit(); // exit if accessed directly
}
And since ABSPATH will not be defined when I run the tests directly, the code was exiting.
This is because, since I told Composer to always load these files each time, this part of the code will execute, while the other files included though autoload PSR will load on demand.
So check to make sure any of the files you included are not stopping the code execution. If it happens, then even when you run phpunit --info the code will still exit and you won't see any output.
I was facing a seems problem. I could run phpunit from root directory but not from anywhere else. so I put the "--configuration" tag, and point it to my xml configuration.
$ ./<path_to_phpunit>phpunit --configuration <path_to_phpunitxml>/phpunit.xml
The path to phpunit is optinal, I used it because I installed locally by composer.
In /composer/vendor/phpunit/phpunit/src/TextUI/Command.php in main() function in catch (Throwable $t) {} block var_dump (echo / print_r) exception. If an exception exists, you, probably, will solve the current problem.

Resources