I've installed FactoryMuffin via composer. After installation, I ran composer dump-autload just to make sure I was using the latest stuff.
Now, when I try to use in my code something from the package I installed I can't. For instance:
use League\FactoryMuffin\Facade;
class APITest extends Sw_Test_PHPUnit_LibraryTestCase
{
public function setUp()
{
$a = new FactoryMuffin();
parent::setUp();
}
}
When I hover over the new FactoryMuffin object instantiation, it says it cannot find its declaration.
If I hover over Facade in:
use League\FactoryMuffin\Facade;
it says
Undefined class Facade
and when hovering over:
use League\FactoryMuffin
it says
multiple implementations
I'm following all the steps listed in the documentation for FactoryMuffin, what am I missing?
Here's my composer file:
{
"name": "project/project",
"description": "Main Project Library",
"homepage": "http://www.testproject.com/",
"require": {
"php": ">=5.4",
"zendframework/zendframework": "2.3.9",
"guzzle/guzzle": "~3.7",
"justinrainbow/json-schema": "~1.3",
"mikey179/vfsStream": "v1.2.0",
"mtdowling/cron-expression": "1.0.*",
"minfraud/http": ">=1.60,<2.0",
"davegardnerisme/nsqphp": "dev-master",
"myclabs/deep-copy": "1.3.0",
"maennchen/zipstream-php": "0.3.*",
"corneltek/getoptionkit": "~2",
"firebase/php-jwt": "~3.0",
"symfony/property-access": "~3.0",
"punic/punic": "2.1.*",
"guzzlehttp/guzzle": "^6.3",
"easypost/easypost-php": "^3.4",
"textalk/websocket": "^1.2",
"robmorgan/phinx": "^0.10.6",
"fzaninotto/faker": "^1.8",
"league/factory-muffin": "^3.0",
"league/factory-muffin-faker": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "5.6.*",
"mockery/mockery": "dev-master"
},
"repositories": [],
"autoload": {
"psr-0": {
"DeepCopy": "vendor/myclabs/deep-copy/src"
}
}
}
https://factory-muffin.thephpleague.com/usage/examples/
Try using as
use League\FactoryMuffin\Facade as FactoryMuffin;
FactoryMuffin::define('Message', array(
'user_id' => 'factory|User',
'subject' => 'sentence',
'message' => 'text',
'phone_number' => 'randomNumber|8',
'created' => 'date|Ymd h:s',
'slug' => 'call|makeSlug|word',
), function ($object, $saved) {
// we're taking advantage of the callback functionality here
$object->message .= '!';
});
Related
I have recently been trying to upgrade from Symfony 6.1 to 6.2. In doing so though..something appears to have broken. Does anyone have any clue what changed from 6.1 to 6.2? I have tried looking and continue to do so..but I haven't been able to find any meaningful change that breaks it. The setup docs all show the same formatting for all the available files.
I am on PHP 8.1.11
When I update my composer.json to bring everything up to 6.2, the console throws the following error:
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! In FileLoader.php line 178:
!!
!! Invalid service id: "MyNamespace\" in /var/www/html/config/services.yaml (whic
!! h is being imported from "/var/www/html/src/Kernel.php").
!!
!!
!! In ContainerBuilder.php line 911:
!!
!! Invalid service id: "MyNamespace\".
!!
!!
!!
Script #auto-scripts was called via post-update-cmd
Nothing has changed, and if I change it all back to 6.1 and reupdate composer..it works just fine.
Below is my services.yaml
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
MyNamespace\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../vendor/'
- '../var/'
_instanceof:
MyNamespace\Enum\AbstractEnumType:
tags: ['app.doctrine_enum_type']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
I have downgraded back to 6.1, that works.
I have tried renaming or removing parts of my class..that doesn't work.
Update: Here is a copy of my kernel file:
namespace MyNamespace;
use MyNamespace\Enum\AbstractEnumType;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function process(ContainerBuilder $container): void
{
$typesDefinition = [];
if ($container->hasParameter('doctrine.dbal.connection_factory.types')) {
$typesDefinition = $container->getParameter('doctrine.dbal.connection_factory.types');
}
$taggedEnums = $container->findTaggedServiceIds('app.doctrine_enum_type');
foreach ($taggedEnums as $enumType => $definition) {
/** #var $enumType AbstractEnumType */
$typesDefinition[$enumType::NAME] = ['class' => $enumType];
}
$container->setParameter('doctrine.dbal.connection_factory.types', $typesDefinition);
}
}
Update 2: I have attached the code for my abstract enum & composer.json
composer.json
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-curl": "*",
"ext-iconv": "*",
"aws/aws-sdk-php": "^3.252",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.7",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.13",
"friendsofsymfony/rest-bundle": "^3.4",
"jms/serializer-bundle": "^4.2",
"monolog/monolog": "^3.2",
"nelmio/cors-bundle": "^2.2",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.9",
"ramsey/uuid": "^4.5",
"stripe/stripe-php": "^9.7.0",
"symfony/amazon-mailer": "6.1.*",
"symfony/apache-pack": "^1.0",
"symfony/console": "6.1.*",
"symfony/dom-crawler": "6.1.*",
"symfony/dotenv": "6.1.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.1.*",
"symfony/http-client": "6.1.*",
"symfony/maker-bundle": "^1.47",
"symfony/mime": "6.1.*",
"symfony/monolog-bundle": "^3.8",
"symfony/property-access": "6.1.*",
"symfony/property-info": "6.1.*",
"symfony/proxy-manager-bridge": "6.1.*",
"symfony/runtime": "6.1.*",
"symfony/security-bundle": "6.1.*",
"symfony/serializer": "6.1.*",
"symfony/twig-bundle": "6.1.*",
"symfony/yaml": "6.1.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true,
"phpstan/extension-installer": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"MyNamespace\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MyNamespace\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.1.*"
},
"public-dir": "/"
},
"require-dev": {
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-symfony": "^1.2",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.1.*",
"symfony/css-selector": "6.1.*",
"symfony/phpunit-bridge": "^6.2",
"symfony/stopwatch": "6.1.*",
"symfony/web-profiler-bundle": "6.1.*"
}
}
AbstractEnumType.php
namespace MyNamespace\Enum;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\StringType;
abstract class AbstractEnumType extends StringType
{
abstract public static function getEnumClass(): string;
public function getName(): string
{
throw new \Exception('getName should be overwritten by child class');
}
public function convertToPHPValue($value, AbstractPlatform $platform): ?\BackedEnum
{
if($value instanceof \BackedEnum){
return $value;
}
$value = parent::convertToPHPValue($value, $platform);
if($value === null){
return null;
}
// 🔥 https://www.php.net/manual/en/backedenum.tryfrom.php
return $this::getEnumClass()::tryFrom($value);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
return $value?->value;
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return 'TEXT';
}
}
I'm working on symfony 2.8 project and I'm new in it. Now I try to upgrade it to the newest version. I found the rector package for update the symfony (rector-prefixed exactly, for older version). I've install it and try to run like it is in documentation: https://github.com/rectorphp/rector, and got this error in the console:
'vendor' is not recognized as an internal or external command,
operable program or batch file.
I've don't found any information about errors like this so I think it could be a problem connect with console error. When I try to write any command for example:
php app/console list
I've got this exception back:
#!/usr/bin/env php
[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.
I don't know exactly where to looking for a problem. I will add my console file code and composer.json, maybe someone have same problem as me.
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
set_time_limit(0);
require __DIR__.'/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": {
"Tixi\\": "src/Tixi/"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
"autoload-dev": {
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
},
"require": {
"php": "~7.4",
"ext-json": "*",
"apy/breadcrumbtrail-bundle": "1.3.*",
"composer/ca-bundle": "~1.2.7",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/doctrine-migrations-bundle": "1.3.*",
"doctrine/orm": "^2.4.8",
"egulias/email-validator": "~1.2",
"friendsofsymfony/oauth-server-bundle": "1.5.*",
"friendsofsymfony/rest-bundle": "1.7.*",
"incenteev/composer-parameter-handler": "~2.0",
"jms/serializer-bundle": "1.5.*",
"knplabs/knp-snappy-bundle": "1.5.*",
"mediaburst/clockworksms": "2.0.*",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.0.2",
"symfony/swiftmailer-bundle": "~2.3,>=2.3.10",
"symfony/symfony": "2.8.*",
"twig/extensions": "1.5.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"rector/rector-prefixed": "^0.9.31",
"sensio/generator-bundle": "~3.0",
"symfony/phpunit-bridge": "~2.7"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"bin-dir": "bin",
"platform": {
"php": "7.4"
},
"sort-packages": true,
"discard-changes": true
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.8-dev"
}
}
}
I solved already the problem. First the problem with Rector was with the command. I don't know exactly why but normal command don't work with my project. In Rector documentation there is:
vendor/bin/rector
command but in my project there works only:
php bin/rector
So this problem was solved. Next I have an issue with any other command form command line. There was a Logic exception. But I handle with this after upgrade the Symfony from 2.8 to 3.x. So I think there was conflict between the oldest version of Symfony and the php 7.4 version.
Following is my directory structure:
|-vendor
|---bin
|---phpunit
|---autoload.php
|---psr
|---sebastian
|---phar-io
|---composer
|---symfony
|-.htaccess
|-composer.lock
|-includes
|---application_top.php
|-routes
|---routes.php
|-modules
|---Controllers
|----CheckoutGatewayController.php
|-tests
|---Controllers
|----tests_common_includes.php
|-composer.phar
I am trying to run ./vendor/bin/simple-phpunit --bootstrap tests/tests_common_includes.php tests/Controllers/CheckoutGatewayTests.php from my base directory but it gives me error Class 'tests/Controllers/CheckoutGatewayTests' could not be found in 'tests/Controllers/CheckoutGatewayTests.php'.
If I try ./vendor/bin/phpunit --bootstrap tests/tests_common_includes.php tests/Controllers/CheckoutGatewayTests.php then I get the error Unable to guess the Kernel directory. I tried to look up symfony's documentation : it suggests using either -c app option or changing phpunit.dist.xml file. But I have neither of those in my directory. There is no xml file and no app folder.
How can I execute my tests? My test file CheckoutGatewayTests.php looks like this :
<?php
use \Controllers\CheckoutGatewayController;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class CheckoutGatewayTests extends WebTestCase {
public function testChargebackCallback() {
$client = static::createClient();
$client->request('GET', '/post/hello-world');
}
}
Edit: my composer.json file
{
"require": {
"guzzlehttp/guzzle": "~6.0",
"psr/log": "^1.0",
"zircote/swagger-php": "^2.0",
"sentry/sentry": "^1.8",
"aws/aws-sdk-php": "^3.52",
"league/flysystem-aws-s3-v3": "~1.0",
"symfony/routing": "^3.4",
"symfony/http-kernel": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/framework-bundle": "^3.4",
"prbdias/mbway-php": "0.1"
},
"require-dev": {
"phpunit/phpunit": "^6"
},
"config": {
"optimize-autoloader": true
},
"autoload": {
"psr-4": {
"": ["modules/", "tests/","routes/"]
}
}
}
Error:
Cell class Audit.AuditCell is missing. Cake\View\Exception\MissingCellException
Plugin files:
plugins/Audit/src/Template/Cell/Audit/model.ctp
plugins/Audit/src/View/Cell/AuditCell.php
In, src/Template/Servers/view.ctp:
echo $this->cell('Audit.Audit::model', [strtolower($this->request->controller), $this->request->pass[0]]);
In, config/bootstrap.php:
Plugin::load('Audit', ['bootstrap' => true, 'routes' => true]);
Using CakePHP 3.3.16.
Edit #1
Snapshot of my IDE:
Edit #2
Relevant parts of my composer.json
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "3.3.*",
"mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0",
"cakephp/plugin-installer": "*",
"adayth/cakephp-cipher-behavior": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "src",
"Audit\\": "./plugins/Audit/src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
"Audit\\Test\\": "./plugins/Audit/tests"
}
I added the proper namespace Audit\View\Cell to my file.
After updating symfony from 2.2 to 2.3, i've got new stange errors on all my pages and in my scripts:
Deprecated: Knp\Menu\Silex\Voter\RouteVoter is deprecated because of namespace, use Knp\Menu\Matcher\Voter\RouteVoter instead. in \vendor\knplabs\knp-menu\src\Knp\Menu\Silex\Voter\RouteVoter.php on line 20
and
Deprecated: Knp\Menu\Silex\RoutingExtension is deprecated, use Knp\Menu\Integration\Symfony\RoutingExtension instead. in \vendor\knplabs\knp-menu\src\Knp\Menu\Silex\RoutingExtension.php on line 15
How could I fix this ? I don't find the answer on the web.
Thank you in advance
Here is my composer.json :
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
"genemu/form-bundle": "2.1.*",
"jms/security-extra-bundle": "1.5.*",
"jms/di-extra-bundle": "1.4.*",
"phpunit/phpunit": "3.7.*",
"doctrine/data-fixtures": "#dev",
"friendsofsymfony/user-bundle": "~2.0#dev",
"stof/doctrine-extensions-bundle": "dev-master",
"knplabs/gaufrette": "0.2.*#dev",
"knplabs/knp-gaufrette-bundle": "dev-master",
"jms/serializer-bundle": "0.13.*#dev",
"amazonwebservices/aws-sdk-for-php": "dev-master",
"punkave/symfony2-file-uploader-bundle": "dev-master",
"oneup/uploader-bundle": "dev-master",
"knplabs/knp-paginator-bundle": "dev-master",
"jms/debugging-bundle": "dev-master",
"winzou/console-bundle": "dev-master",
"elao/web-profiler-extra-bundle" : "dev-master",
"cybernox/amazon-webservices-bundle": ">=1.5.4",
"genemu/form-bundle": "2.2.*",
"escapestudios/wsse-authentication-bundle": "2.3.x-dev",
"rezzza/flickr-bundle": "1.0.*#dev",
"knplabs/knp-menu-bundle": "dev-master",
"genemu/form-bundle": "2.1.*",
"leaseweb/api-caller-bundle": "*",
"eo/honeypot-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "alpha",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
}
}
}
and my menu builder:
namespace ...\Menu;
use Knp\Menu\Matcher\Matcher;
use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;
use Symfony\Component\DependencyInjection\ContainerAware;
class Builder extends ContainerAware
{
public function mainMenu(MenuFactory $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Dashboard', array(
'route' => 'dashboard' ));
$menu->addChild('Color Scheme', array(
'uri' => 'slidescheme' ));
$menu->addChild('Questionnnaires', array(
'uri' => 'questionnaire_manage' ));
// ... add more children
return $menu;
}
}
The issue is that you're using a dev version of knplabs/menu. Edit your composer file from:
"knplabs/knp-menu-bundle": "dev-master",
to:
"knplabs/knp-menu-bundle" : "~1.1",
and the error message will go away. Note that if you're actually using dev features of knplabs/menu (like Matcher and Voter) those won't be available any more. But Symfony does not require them anyway.
It's not a good idea update your symfony version in the middle of a develpment. Actually, it's a bad idea upgrade any bundle you are using in your code (there's always exceptions, but this is the general rule).
In your case, the bundle has been refactored in this new version, so now it's not compatible with the code you have written . I'm afraid you only have two alternatives:
Adapt your code to the new requirements
Or change your composer again to use symfony 2.2 and run composer update
I strongly suggest the second option if you already have many lines of code written.