I'm using phpunit for test.
I've put the autoload, psr-4 in cofiguration.json
{
"require-dev": {
"phpunit/phpunit": "^7.5"
},
"autoload": {
"psr-4":{
"Src\\": "src/"
}
}
}
After that, I executed this command in cmd composer dump-autoload, and the test doesn't work. The outputs are that:
C:\xampp\htdocs\phpUnitPractice>.\vendor\bin\phpunit tests\EasyTest.php
PHP Fatal error: Uncaught Error: Class "PHPUnit\TextUI\Command" not found in C:\xampp\htdocs\phpUnitPractice\vendor\phpunit\phpunit\phpunit:61
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\phpUnitPractice\vendor\phpunit\phpunit\phpunit on line 61
Fatal error: Uncaught Error: Class "PHPUnit\TextUI\Command" not found in C:\xampp\htdocs\phpUnitPractice\vendor\phpunit\phpunit\phpunit:61
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\phpUnitPractice\vendor\phpunit\phpunit\phpunit on line 61
That information goes inside composer.json not configuration.json, have a look at this composer.json example. Then run composer dump-autoload.
So, you should have a file like this:
{
"require": {
YOUR REQUIRES
},
"require-dev": {
"phpunit/phpunit": "^7.5"
},
"autoload": {
"psr-4":{
"Src\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
}
Related
Last days I try to upgrade my project step by step. I have Symfony 2.8, composer 2. Lately I found rector/rector package for upgrading, but there was conflicts when I try to install it. Next I try to install rector/rector-prefixed. It also gives many problems with installation, but after research I've update my php version to 7.4 and it goes good. I've made composer update and install, but in the meantime new error shows up. With AppKernel. Before there was everything good and the app works fine. Now I've got message in the browser: Composer detected issues in your platform: "Your Composer dependencies require a PHP version ">= 7.4.0". "
And in the console after every command (for example: php app/console list) now I'm getting this message:
#!/usr/bin/env php
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TixiCoreDomainBundle" from namespace "Tixi\CoreDomainBundle".
Did you forget a "use" statement for "Tixi\CoreDomainBundle\TixiCoreDomainBundle"? in C:\Users\Developer\PhpstormProjects\sfitixi\app\AppKernel.php:32
Stack trace:
#0 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(427): AppKernel->registerBundles()
#1 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()
#3 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Compone in C:\Users\Developer\Phpstor
mProjects\sfitixi\app\AppKernel.php on line 32
Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TixiCoreDomainBundle" from namespace "Tixi\CoreDomainBundle".
Did you forget a "use" statement for "Tixi\CoreDomainBundle\TixiCoreDomainBundle"? in C:\Users\Developer\PhpstormProjects\sfitixi\app\AppKernel.php:32
Stack trace:
#0 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(427): AppKernel->registerBundles()
#1 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(128): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php(62): Symfony\Component\HttpKernel\Kernel->boot()
#3 C:\Users\Developer\PhpstormProjects\sfitixi\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php(117): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Compone in C:\Users\Developer\Phpstor
mProjects\sfitixi\app\AppKernel.php on line 32
This is what I have in AppKernel.php:
public function registerBundles(): array
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Tixi\CoreDomainBundle\TixiCoreDomainBundle(),
new Tixi\ApiBundle\TixiApiBundle(),
new Tixi\SecurityBundle\TixiSecurityBundle(),
new Tixi\App\AppBundle\TixiAppBundle(),
new FOS\RestBundle\FOSRestBundle(),
new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new APY\BreadcrumbTrailBundle\APYBreadcrumbTrailBundle(),
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
I've tried to write use statements but it didn't change anything.
My composer.json:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": {
"Tixi\\": "src/"
},
"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"
}
}
}
Anyone have idea how to fix this?
EDIT (11.03.2021)
Yes, the class exist. The problem is with every 4 class with namespace begin with Tixi. This class are empty and they extends Bundle class from Symfony. They are like this:
<?php
namespace Tixi\ApiBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Class TixiApiBundle
* #package Tixi\ApiBundle
*/
class TixiApiBundle extends Bundle
{
}
And the place of this classes pass with they namespace.
EDIT: 18.03
After changing the namespace in composer.json for auto load I have another error, this time with running scripts from composer.json. This is the error message:
> post-install-cmd: #symfony-scripts
> symfony-scripts: Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> symfony-scripts: Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
#!/usr/bin/env php
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command:
#!/usr/bin/env php
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
.
Exception trace:
() at C:\Users\Developer\PhpstormProjects\sfitixi\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:326
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeCommand() at C:\Users\Developer\PhpstormProjects\sfitixi\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Composer\ScriptHandler.php:138
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:341
Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:220
Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:87
Composer\EventDispatcher\EventDispatcher->dispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:200
Composer\EventDispatcher\EventDispatcher->doDispatch() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php:102
Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php:341
Composer\Installer->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Command/InstallCommand.php:136
Composer\Command\InstallCommand->execute() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Command/Command.php:245
Symfony\Component\Console\Command\Command->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:835
Symfony\Component\Console\Application->doRunCommand() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:185
Symfony\Component\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:310
Composer\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Application.php:117
Symfony\Component\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:122
Composer\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/bin/composer:63
require() at C:\ProgramData\ComposerSetup\bin\composer.phar:24
The autoloader is not configured properly:
"autoload": {
"psr-4": {
"Tixi\\": "src/"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
This tells the autoloader to search for all classes in the Tixi namespace in src. According to this, the class Tixi\CoreDomainBundle\TixiCoreDomainBundle should be located at src/CoreDomainBundle/TixiCoreDomainBundle.php, but it is located at src/Tixi/CoreDomainBundle/TixiCoreDomainBundle.php.
Either move everything from the Tixi subfolder one level up, or adjust your classloader settings - changing it to src/Tixi/ could help
I am making my own framework but I have a problem with psr4 autoload and composer.
I can not make classes available and apparently everything is fine
This is the error, I don't want to use include for class files:
Fatal error: Uncaught Error: Class 'System\Template\get_template_files_class' not found in /var/www/html/fsib/system/layout-compiler.php:7 Stack trace: #0 {main} thrown in /var/www/html/fsib/system/layout-compiler.php on line 7
composer.json
{
"require": {
"illuminate/database": "*",
"illuminate/routing": "~5.1.16",
"illuminate/events": "~5.1.16"
},
"autoload": {
"psr-4": {
"System\\" : "system/libs/"
}
}}
layout-compiler.php
<?php
require_once '../vendor/autoload.php';
use System\Template\get_template_files_class;
$templates = new get_template_files_class;
?>
get_templates_files_class.php
<?php
namespace System\Template
class get_template_files_class {
}
?>
I have to learn just now write mobile app web service via fire base.
I followed this link: https://firebase-php.readthedocs.io/en/stable/
In my core website i create web service folder and then create my fire.php file.This file code here,
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyC_vb5G9qs3NJsywbR34el1RaPj2HDhwNg';
$firebase = (new Factory)
->withServiceAccountAndApiKey($serviceAccount, $apiKey)
->withDatabaseUri('https://workarea-cb10b.firebaseio.com')
->create();
$database = $firebase->getDatabase();
$newPost = $database
->getReference('blog/posts')
->push([
'title' => 'Post title',
'body' => 'This should probably be longer.'
]);
$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
$newPost->getUri(); // => https://my-project.firebaseio.com/blog/posts/-KVr5eu8gcTv7_AHb-3-
$newPost->getChild('title')->set('Changed post title');
$newPost->getValue(); // Fetches the data from the realtime database
$newPost->remove();
I have to call my support file here: https://github.com/kreait/firebase-php/
But still I got a:
Fatal error: Uncaught Error: Class 'Kreait\Firebase\ServiceAccount'
not found in
/opt/lampp/htdocs/workarea/webservice/firebase/fire.php:13 Stack
trace: #0 {main} thrown in
/opt/lampp/htdocs/workarea/webservice/firebase/fire.php on line 13
issue have to fix this issue. Kindly check and help me.
My composer.json file
{
"name": "kreait/firebase-php",
"description": "Firebase Admin SDK",
"keywords": ["firebase", "google", "sdk", "api", "database"],
"homepage": "https://github.com/kreait/firebase-php",
"license": "MIT",
"authors": [
{ "name": "Jérôme Gamez", "homepage": "https://github.com/jeromegamez" }
],
"require": {
"php": "^7.0",
"ext-mbstring": "*",
"ext-openssl": "*",
"fig/http-message-util": "^1.1",
"google/auth": "^0.11.0|^1.0",
"guzzlehttp/guzzle": "^6.2.1",
"kreait/firebase-tokens": "^1.1.1",
"lcobucci/jwt": "^3.2",
"mtdowling/jmespath.php": "^2.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"phpstan/phpstan-phpunit": "^0.9.2",
"phpunit/phpunit": "^6.0"
},
"autoload": {
"psr-4": {
"Kreait\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Kreait\\Tests\\": "tests"
}
},
"config": {
"platform": {
"php": "7.0"
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
}
}
I am sure you already got your problem solved, but for upcoming developers it might be helpful, Its issue with your composer install kreait/firebase-php using composer in cmd inside project directory and your issue will be resolved.
I actually had the same issue and I address it by install php-psr exteion:
pecl install psr
Created /etc/php/7.x/mods-available/psr.ini with the following lines:
; configuration for psr module
; priority=20
extension=psr.so
and enable the extension by excuting:
sudo phpenmod psr
and reload/restart apache, php-fpm.....
service apache2 restart
service php7.4-fpm restart
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.
I'm trying to create a MVC structure and use composer to autoload everything.
But I keep getting this error:
Fatal error: Uncaught Error: Class 'App\Init' not found in C:\wamp64\www\activity\Public\index.php on line 5
|MainFolder
|App
|Public
|Vendor
|ACT
|composer
|autoload.php
|composer.json
composer.json:
{
"name": "vendor/activity",
"description": "descrip",
"require": {
"php": ">=5.6.25"
},
"authors":[
{
"name": "John Doe",
"email": "johndoe#gmail.com"
}
],
"autoload":{
"psr-4": {
"ACT\\": "vendor/",
"App\\": "/"
}
},
"config":{
"bin-dir": "bin"
}
}
App\init.php
<?php
namespace App;
class Init
{
public function __construct()
{
echo "Loaded!!";
}
}
Public\index.php
<?php
require_once '../vendor/autoload.php';
$init = new \App\Init;
\Vendor\composer\autoload_namespaces.php
<?php
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
"ACT" => array($vendorDir . false),
"App" => array($baseDir . '/'),
);
Obs: Already did composer dump-autoload
Don't manually put things in /vendor.
While adhering to #1, don't reference /vendor in autoload, the packages should all have their own fully-functionaly autoloaders that composer will find and use.
You need to specify more of the path in your autoload.
"autoload":{
"psr-4": {
"App\\": "App/"
}
},
Think of it like telling composer "look for things starting with the namespace foo\bar\ in the following folder".
Note: The folder name doesn't have to match the namespace.
Eg: Following the suggested Vendor\Package\ scheme for PSR/Composer
{
"autoload": {
"psr-4": {
"sammitch\\meatstacker\\": "src/"
}
}
}
And then:
\sammitch\meatstacker\Client maps to src/Client.php
\sammitch\meatstacker\Bread\Rye maps to src/Bread/Rye.php
and so on