I know you can run all datafixtures by running this command:
php app/console doctrine:fixtures:load
And that you can run a specific fixture by running this command:
php app/console doctrine:fixtures:load --fixtures=/path/to/fixture1
But now I'm trying the second command to load a specific datafixture like this:
php app/console doctrine:fixtures:load --fixtures=/src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM/LoadRegionData
My LoadRegionData class is located at:
src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM/LoadRegionData.php
When I run the command I always get the following error:
[InvalidArgumentException]
Could not find any fixtures to load in:
- /src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM/LoadRegionData
LoadRegionData.php
<?php
namespace VolleyScout\VolleyScoutBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use VolleyScout\VolleyScoutBundle\Entity\Regions;
class LoadRegionData implements FixtureInterface
{
/**
* {#inheritDoc}
*/
public function load(ObjectManager $manager)
{
$regions = ['West-Vlaanderen', 'Oost-Vlaanderen', 'Antwerpen', 'Vlaams-Brabant', 'Limburg', 'Vlaanderen'];
foreach($regions as $r){
$region = new Regions();
$region->setRegionName($r);
$region->setRegionDescription($r);
$manager->persist($region);
$manager->flush();
}
}
}
?>
try
php app/console doctrine:fixtures:load --fixtures=src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM
Try it with the full path:
php app/console doctrine:fixtures:load --fixtures=/Users/foobar/projects/projectname/src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM
Related
I have already developed project in laravel and i'm setting up it in my local computer but after running php artisan serve i'm getting this error
PHP Fatal error: Uncaught ReflectionException: Class App\Console\Kernel does not exist in C:\xampp\htdocs\translate\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
I don't know what is wrong but I have tried everything that I have found on internet
composer update
composer dump-autoload
composer self-update
php artisan config:clear
php artisan cache:clear
none of that command worked for me
You must run composer install for installing the new dependencies.
Since you mentioned that you have issues with your other artisan commands delete everything inside the bootstrap->cache folder, except of the .gitignore file of course, manually and then run php artisan optimize
That way your "corrupted" cache will be recreated and reconfigured.
First thing you must do is to make sure your artisan commands are working right, so do the caching fix i suggest first. Then you can run the composer commands you mentioned also in your question.
Check you have this file in app/Console folder
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
/*$schedule->command('users:update')->everyMinute();
$schedule->command('servers:update')->everyMinute();*/
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
I am developing a package for Laravel 5.8. When I try to create a console command that extends Illuminate\Console\Command then "composer dump-autoload" fails with error message:
c:\Program Files (x86)\Ampps\www\ptest>composer dump-autoload
Generating optimized autoload files> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
ReflectionException : Class TestVendor\TestPackage\TestCommand does not exist
at C:\Program Files (x86)\Ampps\www\ptest\vendor\laravel\framework\src\Illuminate\Container\Container.php:790
786| if ($concrete instanceof Closure) {
787| return $concrete($this, $this->getLastParameterOverride());
788| }
789|
> 790| $reflector = new ReflectionClass($concrete);
791|
792| // If the type is not instantiable, the developer is attempting to resolve
793| // an abstract type such as an Interface or Abstract Class and there is
794| // no binding registered for the abstractions so we need to bail out.
Exception trace:
1 ReflectionClass::__construct("TestVendor\TestPackage\TestCommand")
C:\Program Files (x86)\Ampps\www\ptest\vendor\laravel\framework\src\Illuminate\Container\Container.php:790
2 Illuminate\Container\Container::build("TestVendor\TestPackage\TestCommand")
C:\Program Files (x86)\Ampps\www\ptest\vendor\laravel\framework\src\Illuminate\Container\Container.php:667
I have tried to create the package by hand inside of C:\Program Files (x86)\Ampps\www\ptest\packages folder and I tried to use the packager https://github.com/Jeroen-G/laravel-packager but the result is identical in both cases.
TestCommand.php
<?php
namespace TestVendor\TestPackage;
use Illuminate\Console\Command;
class TestCommand extends Command {
protected $signature = 'test:hello';
protected $description = 'say hello';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info("hello!");
}
}
TestServiceProvider.php
<?php
namespace TestVendor\TestPackage;
use Illuminate\Support\ServiceProvider;
class TestServiceProvider extends ServiceProvider
{
public function boot()
{
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/testpackage.php', 'testpackage');
$this->app->singleton('testpackage', function ($app) {
return new TestPackage;
});
}
public function provides()
{
return ['testpackage'];
}
protected function bootForConsole()
{
// Registering package commands.
$this->commands([TestCommand::class]);
}
}
When I execute the TestCommand.php file directly from command line it fails with the error message
PHP Fatal error: Class 'Illuminate\Console\Command' not found
I have checked other working packages inside "Vendor" folder and all have the same structure as my package. It seems as if autoloading does not work properly.
The "console" folder was outside of "src" folder. Therefore it could not be discovered.
remove vendor and node_modules folder
then run following commands
composer update
npm install
it should work fine.
I try to add this code in my DefaultControllerTest
$load = new Loader();
$load->load('src/AppBundle/DataFixtures/ORM/product.yml');
and here is the complete code of my controller
<?php
namespace Tests\AppBundle\Controller;
use Nelmio\Alice\Fixtures\Loader;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$load = new Loader();
$load->load('src/AppBundle/DataFixtures/ORM/product.yml');
$client = static::createClient();
$crawler = $client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
}
}
If I run phpunit. It works and no errors found. It successfully tested but the problem here the product.yml doesn't insert any data in my database. But If I run this command bin/console hautelook_alice:doctrine:fixtures:load --append. This will works. It insert the data. How can I load the datafixture before I test the controller? I try to research more about it. but I have no clue on how to add it now.
You can simply use a bash script. Something like this (adapt to your needs):
#!/bin/bash
echo "# Refresh data model and load fixtures"
php bin/console doctrine:database:create --if-not-exists --env=dev
php bin/console doctrine:schema:drop --force --env=dev
php bin/console doctrine:schema:create --env=dev
php bin/console doctrine:schema:validate --env=dev
php bin/console hautelook_alice:doctrine:fixtures:load --append --env=dev
echo -e " --> DONE\n"
Then you can launch phpunit that will use this fresh database. Or you could just add the phpunit call in this script:
./bin/simple-phpunit --debug --verbose
I'm trying to write some functional tests for a Symfony2 app.
Those tests interacts with the database, using, obviously, Doctrine.
Now, I setup the configuration to call the test database, but it is empty and has no tables, so my tests fail.
How can I build the database schema into the test database before the execution of the tests?
I have tried this
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class GetStartedControllerTest extends WebTestCase
{
public function setUp()
{
passthru(sprintf('php "%s/console" cache:clear --env=test --no-warmup --no-interaction', __DIR__));
passthru(sprintf('php "%s/console" doctrine:database:drop --env=test --force --no-interaction', __DIR__));
passthru(sprintf('php "%s/console" doctrine:database:create --env=test --no-interaction', __DIR__));
passthru(sprintf('php "%s/console" doctrine:schema:update --force --env=test --no-interaction', __DIR__));
}
/**
*
*/
public function testRegisterNewUser()
{
...
But it seems not working...
Any ideas? Thank you!
I have a Symfony2 application. In one bundle, I have a command class inside a Command folder; then, when I try to execute:
php app/console doctrine:database:[something]
I get:
[InvalidArgumentException]
There are no commands defined in the "doctrine:database" namespace.
BUT, if I rename the Command folder (Command_ for example), the exception does not appear and all runs well, the problem is that I cannot use the command if the Command folder's name isn't 'Command'.
Here's may code:
RunMigrationXCommand.php:
<?php
#!/usr/bin/env php
// app/console
use Symfony\Component\Console\Application;
use eCommerce\MigrationBundle\Command\MigrationXCommand;
$application = new Application();
$application->add(new MigrationXCommand);
$application->run();
And MigrationXCommand.php:
class MigrationXCommand extends ContainerAwareCommand {
protected function configure() {
parent::configure();
$this
->setName('migrationX')
->setDescription('Migration BBDD')
->addArgument(
'argument', InputArgument::OPTIONAL, 'What do you want to migrate?'
);
}
protected function execute(InputInterface $input, OutputInterface $output) {
// ...
}
Any fix?