When I run the test of my page, I encounter this error message that I do not have on the browser:
Error: Unable to access jarfile ./../src/Java/File.jar
Here is the call to the file in my controller (symfony 4):
exec("java -jar ./../src/Java/File.jar $params",$tab);
Here is my test method :
public function testView(){
$crawler = $this->client->request('GET','/test/1');
if( Response::HTTP_OK !== $this->client->getResponse()->getStatusCode()){
echo $crawler->filter('div.exception-message-wrapper')->text();
echo $crawler->filter('.trace-html-1')->text();
}
static::assertEquals(
Response::HTTP_OK,
$this->client->getResponse()->getStatusCode()
);
}
thanks for your help
In your controller you could try using a path to the jar which will be relative to the __DIR__.
exec("java -jar " . __DIR__ . "../src/Java/File.jar $params", $tab);
To understand, you can read more about __DIR__ here
Getting an error PHP Warning: GearmanClient::do(): _client_do(GEARMAN_TIMEOUT) occured during gearman_client_run_tasks() while running client script.
//------------worker.php
#!/usr/bin/php -q
<?php
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction( "test" , "test_function" );
while ($worker->work());
function test_function( $job )
{
return strtoupper($job->workload());
}
?>
//------------client.php
<?php
$client = new GearmanClient();
$client->addServer();
$client->setTimeout(1000);
print "\n";
print $client->do( "test" , "this is a test" );
die();
?>
Use nohub posix command to run the worker in the background
run worker using below command
nohup /usr/bin/php worker.php > /dev/null 2>&1 &
run client using below command
php client.php
I'm very new to Symfony and I'm trying to automate the deploy process with rsync, while keeping both the local and remote installs of Symfony working.
What I've done so far:
installed Cygwin on my local machine (Windows 7+Apache2.2+PHP 5.3+MySQL 5.1)
done a basic Symfony install on my local machine from shell with the command
php composer.phar create-project symfony/framework-standard-edition [path]/ 2.2.1
set up a remote LAMP Ubuntu server with php-fpm (fastcgi)
set up two different configuration files for local and remote in the app/config/ dir, parameters.yml and parameters.yml.remote
created an app/config/rsync_exclude.txt file containing a list of files not to rsync to the remote server (as suggested in this page)
created a deploy shell script that I run from Cygwin (see below)
The deploy script issues the commands:
rsync -avz /cygdrive/c/[path]/ user#server:[remote-path]/ --exclude-from=/cygdrive/c/[path]/app/config/rsync_exclude.txt
ssh user#server 'cd [remote-path]/ && php app/console --env=prod cache:clear && php app/console cache:clear'
ssh user#server 'mv [remote-path]/app/config/parameters.yml.remote ~/[remote-path]/app/config/parameters.yml'
The rsync, ssh and mv commands work, but the deployed site shows always a HTTP 500 error (both app.php and app_dev.php).
Looking at server error log the error is:
Fatal error: Class 'Composer\\Autoload\\ClassLoader' not found in /[remote-path]/vendor/composer/autoload_real.php on line 23
Any clue would be more than welcome.
Edit - here is my vendor/composer/autoload_real.php file (sorry for the making the question longer!):
<?php
// autoload_real.php generated by Composer
class ComposerAutoloaderInit9d50f07556e53717271b583e52c7de25
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit9d50f07556e53717271b583e52c7de25', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
// ^^^^^^ this is line 23 and gives the error ^^^^^^^^^^^
spl_autoload_unregister(array('ComposerAutoloaderInit9d50f07556e53717271b583e52c7de25', 'loadClassLoader'));
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->add($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
require $vendorDir . '/kriswallsmith/assetic/src/functions.php';
require $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php';
return $loader;
}
}
If there is an error with the autoloader generated by composer, performing ...
composer update
... will update your dependencies and create a new one.
You should invoke the command with the -o flag if you are deploying to a production system.
This way composer generates a classmap autoloader ( which performs way better ) instead of the classic autoloader.
composer update -o
I guess re-generating the autoloader will solve the issue :)
I seem to have a slight problem with executing PHPUnit tests for own modules in the Zend Framework 2.
OS: Mac OS 10.8.3
Zend Framework 2.1.4
PHPUnit Version 3.7.19 (installed via pear)
PHP Version 5.3.15 (xdebug enabled, version 2.1.3)
I followed the instructions of the Zend guideline, to create the module "Album" (http://framework.zend.com/manual/2.1/en/user-guide/modules.html)
Instead of putting the unit tests into the module folders, I want to have them all in one centralized folder. This is the base structure of my application:
-config
-data
-module
-public
-tests
--Modules
---Album
----AlbumTest.php
--Bootstrap.php
--phpunit.xml
-vendor
...(license, readme, composers and init_autoloader.php)
-> The test for the Module Album resides in a folder "Modules/Album" in "tests". The folder "tests" contains also the Bootstrap.php and phpunit.xml.
Here is the content of the files:
Bootstrap.php
<?php
/*
* Set error reporting to the level to which Zend Framework code must comply.
*/
error_reporting( E_ALL | E_STRICT );
/*
* The first run required me to fix some constants
*/
defined('TESTS_ZEND_FORM_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_FORM_RECAPTCHA_PUBLIC_KEY', 'public key');
defined('TESTS_ZEND_FORM_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_FORM_RECAPTCHA_PRIVATE_KEY', 'private key');
defined('TESTS_ZEND_LDAP_PRINCIPAL_NAME') || define('TESTS_ZEND_LDAP_PRINCIPAL_NAME', 'someUser#example.com');
defined('TESTS_ZEND_LDAP_ALT_USERNAME') || define('TESTS_ZEND_LDAP_ALT_USERNAME', 'anotherUser');
chdir(dirname(__DIR__));
/*
* autoload the application
*/
include __DIR__ . '/../init_autoloader.php';
Zend\Mvc\Application::init(include 'config/test.config.php');
phpunit.xml
<phpunit bootstrap="./Bootstrap.php" colors="true">
<testsuites>
<testsuite name="Zend Module Tests">
<directory>./Modules</directory>
</testsuite>
</testsuites>
</phpunit>
AlbumTest.php
<?php
namespace AlbumTest\Model;
use Album\Model\Album;
use PHPUnit_Framework_TestCase;
/**
* #category Module
* #package Album
* #subpackage UnitTests
* #group Module_Album
*/
class AlbumTest extends PHPUnit_Framework_TestCase {
public function testAlbumInitialState() {
$album = new Album();
$this->assertNull($album->artist, '"artist" should initially be null');
$this->assertNull($album->id, '"id" should initially be null');
$this->assertNull($album->title, '"title" should initially be null');
}
public function testExchangeArraySetsPropertiesCorrectly() {
$album = new Album();
$data = array('artist' => 'some artist',
'id' => 123,
'title' => 'some title');
$album->exchangeArray($data);
$this->assertSame($data['artist'], $album->artist, '"artist" was not set correctly');
$this->assertSame($data['id'], $album->id, '"id" was not set correctly');
$this->assertSame($data['title'], $album->title, '"title" was not set correctly');
}
public function testExchangeArraySetsPropertiesToNullIfKeysAreNotPresent() {
$album = new Album();
$album->exchangeArray(array('artist' => 'some artist',
'id' => 123,
'title' => 'some title'));
$album->exchangeArray(array());
$this->assertNull($album->artist, '"artist" should have defaulted to null');
$this->assertNull($album->id, '"id" should have defaulted to null');
$this->assertNull($album->title, '"title" should have defaulted to null');
}
public function testGetArrayCopyReturnsAnArrayWithPropertyValues() {
$album = new Album();
$data = array('artist' => 'some artist',
'id' => 123,
'title' => 'some title');
$album->exchangeArray($data);
$copyArray = $album->getArrayCopy();
$this->assertSame($data['artist'], $copyArray['artist'], '"artist" was not set correctly');
$this->assertSame($data['id'], $copyArray['id'], '"id" was not set correctly');
$this->assertSame($data['title'], $copyArray['title'], '"title" was not set correctly');
}
public function testInputFiltersAreSetCorrectly() {
$album = new Album();
$inputFilter = $album->getInputFilter();
$this->assertSame(3, $inputFilter->count());
$this->assertTrue($inputFilter->has('artist'));
$this->assertTrue($inputFilter->has('id'));
$this->assertTrue($inputFilter->has('title'));
}
}
NetBeans knows, where to find the phpunit binaries:
(I wanted to post images here, don't have the reputation though :), I will try to explain it)
The paths to are configured in the options - php - unit testing
/usr/local/pear/bin/phpunit and
/usr/local/pear/bin/phpunit-skelgen
In the properties of the project I set the "Use XML Configuration" and pasted the path to the phpunit.xml. I also checked "Ask for Test Groups Before Running Tests" - I gave the test above the group "Module_Album" - like this I make sure, that PHPUnit finds the right test.
I right click on Project and choose "Test", it shows me the group "Module_Album", I check it and click "Ok". It runs something, tells me it located the right phpunit.xml ("Configuration read from FULL_PATH/tests/phpunit.xml"). After running, it tells me, that it didn't execute any tests.
This is the full output in NetBeans:
PHPUnit 3.7.19 by Sebastian Bergmann.
Configuration read from FULL_PATH/tests/phpunit.xml
Time: 9 seconds, Memory: 348.25Mb
[2KNo tests executed!
[2K
Generating code coverage report in Clover XML format ... done
Anyway, I can do the same successfully via shell (terminal). It doesn't matter, if I directly mount the tests directory and run phpunit, use the full path to the phpunit binary (to make sure, that I don't use different version), specifying the full path of the phpunit.xml, and so on. Here are some samples:
phpunit
phpunit -c FULL_PATH/tests/phpunit.xml
/usr/local/pear/bin/phpunit -c FULL_PATH/tests/phpunit.xml
All of these commands give me, what I expect:
PHPUnit 3.7.19 by Sebastian Bergmann.
Configuration read from FULL_PATH/tests/phpunit.xml
.....
Time: 0 seconds, Memory: 12.75Mb
OK (5 tests, 16 assertions)
I don't get, why this works in shell but not via NetBeans
NetBeans uses 350MB, while in shell it uses only 12.75MB
In case I remove the option "Ask for Test Groups Before Running Tests", it seems to try running all ZendTests. Don't know how this is possible, from the phpunit.xml it should not find them.
Any help is appreciated, thanks!
I finally figured out, what is going on. I ran previously the ZendTests with the phpunit.xml, which is inside vendor/zendframework/zendframework/tests
For some reason NetBeans saves the testfile-directory, which it finds in the first test run and doesn't release them, if the a different phpunit.xml is chosen. I had to change the path of my "new" tests directory via "Right click on project" - "Properties" - "Sources" - "Test Folder".
Now NetBeans runs the test and gives exactly the same output like CLI.
In my Symfony 2.1 app, I'm unable to run the recommended phpunit -c app/. I get the following error message (I added linebreaks):
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /symfony2-dual-auth/app/phpunit.xml.dist
F
PHP Fatal error: main(): Failed opening required
'/symfony2-dual-auth/vendor/symfony/symfony/vendor/autoload.php'
(include_path='.:/usr/share/php:/usr/share/pear')
in /symfony2-dual-auth/vendor/symfony/symfony/autoload.php.dist on line 3
Complete source code here: https://github.com/meonkeys/symfony2-dual-auth . Except the test, since it doesn't pass. Here's src/Oh/FOSFacebookUserBundle/Tests/SimpleFunctionalTest.php...
<?php
namespace Oh\FOSFacebookUserBundle\Tests;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\WebTestCase;
class SimpleFunctionTest extends WebTestCase {
public function testIndex() {
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$this->assertEquals(1, $crawler->filter('html:contains("Remember me")')->count());
}
}
I was extending the wong class. Here's the fix:
-use Symfony\Bundle\FrameworkBundle\Tests\Functional\WebTestCase;
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;