When running codecept run -vvv I get an error stating that the actor is undefined in the SuiteManager class (method is initialize).
Any guess on how to fix this?
I've set up two basic unit tests where I just want to assert some values, and they worked until I switched to the composer autoloader.
In the composer.json I have the following:
"autoload": {
"classmap": [
"app"
]
},
"require-dev": {
"codeception/codeception": "^2.3",
"phpstan/phpstan": "^0.8.0",
"symfony/console": "^3.3"
}
In the main _bootstrap file provided by Codeception I only have a require_once for the vendor autoloader file.
Using php 7.1 and latest versions of the packages.
Related
I have wamp64, php 7.4 and using composer I ran this from the console
composer create-project --prefer-dist "cakephp/app:^4.0" myapp
and
composer create-project --prefer-dist cakephp/app:~4.0 my_app_name
The installation cut out towards the end with this error
Script App\Console\Installer::postInstall handing the post create project cmd event terminated with an exception
[Symfony\Component\Console\Exception\RunTimeException\ Aborted
and some Symfony runtime exception when you get to the set folder permission y/n
It created this JSON file
{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "https://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"php": ">=7.2",
"cakephp/cakephp": "~4.2.0",
"cakephp/migrations": "^3.0",
"cakephp/plugin-installer": "^1.3",
"mobiledetect/mobiledetectlib": "^2.8"
},
"require-dev": {
"cakephp/bake": "^2.3",
"cakephp/cakephp-codesniffer": "~4.2.0",
"cakephp/debug_kit": "^4.4",
"josegonzalez/dotenv": "^3.2",
"phpunit/phpunit": "~8.5.0 || ^9.3",
"psy/psysh": "#stable"
},
"suggest": {
"markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
"dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan/Psalm compatibility.",
"phpstan/phpstan": "PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code."
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"check": [
"#test",
"#cs-check"
],
"cs-check": "phpcs --colors -p src/ tests/",
"cs-fix": "phpcbf --colors -p src/ tests/",
"stan": "phpstan analyse",
"test": "phpunit --colors=always"
},
"prefer-stable": true,
"config": {
"sort-packages": true
}
}
How to Fix Cakephp 4 Composer Install Error
(i didnt understand the solution to this)
Cakephp 4 Windows Installation Issues
It should be possible to get it to work. What Windows version do you use? Pro or Home? Which distribution? 2010?
Please make sure to navigate to the WAMP install folder and then specifically the www folder.
The command I use is this;
composer create-project --prefer-dist cakephp/app:~4.0 cake
It worked for me.
Alternatively, download Cakephp version 4.0, place the contents in the www folder, and configure it manually through the file /config/app.php. If you want, we can look at it together. There are not many people around me that can or want to work on Cakephp, so it'd be a pleasure. :)
To make this more interesting, things work just fine if I run composer dump-autoload -o but I am curious why would this throw an error when I run composer update in the first place? I need to get to the bottom of this. A quick fix doesn't make me happy internally.
aligajani at Alis-MBP in ~/Projects/saveeo on master ✗ [faaba41c] 4:53
> composer update
> php artisan clear-compiled
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Generating autoload files
> php artisan optimize
[ReflectionException]
Class Saveeo\Board\Observers\BoardEventListener does not exist
BoardEventListener.php (placed in Saveeo/Board/Observers)
<?php
namespace Saveeo\Board\Observers;
use Saveeo\Services\HashIds\Contracts\HashIds as HashIdService;
class BoardEventListener {
private $hashIdService;
public function __construct(HashIdService $hashIdService) {
$this->hashIdService = $hashIdService;
}
public function whenBoardIsCreated($event) {
$this->hashIdService->syncHashIdValueOnModelChanges($event, 'board');
}
public function whenBoardIsUpdated($event) {
$this->hashIdService->syncHashIdValueOnModelChanges($event, 'board');
}
public function subscribe($events) {
$events->listen(
'Saveeo\Board\Observers\Events\BoardHasBeenCreated',
'Saveeo\Board\Observers\BoardEventListener#whenBoardIsCreated'
);
$events->listen(
'Saveeo\Board\Observers\Events\BoardHasBeenUpdated',
'Saveeo\Board\Observers\BoardEventListener#whenBoardIsUpdated'
);
}
}
EventServiceProvider.php (placed in Saveeo/Providers)
<?php
namespace Saveeo\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* #var array
*/
protected $listen = [
//
];
/**
* The subscriber classes to register.
*
* #var array
*/
protected $subscribe = [
'Saveeo\Board\Observers\BoardEventListener',
];
/**
* Register any other events for your application.
*
* #param \Illuminate\Contracts\Events\Dispatcher $events
* #return void
*/
public function boot(DispatcherContract $events) {
parent::boot($events);
//
}
}
Here is the folder structure. Can't see anything wrong here?
https://imgur.com/BI44Lq6
Composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"firebase/php-jwt": "~2.0",
"guzzlehttp/guzzle": "5.*",
"guzzlehttp/oauth-subscriber": "0.2.0",
"laravel/socialite": "2.*",
"league/flysystem-aws-s3-v3": "~1.0",
"aws/aws-sdk-php": "3.*",
"bugsnag/bugsnag-laravel": "1.*",
"vinkla/hashids": "^2.3"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"tymon/jwt-auth": "0.5.*",
"symfony/dom-crawler": "~3.0",
"symfony/css-selector": "~3.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Saveeo\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
It looks like we changed the autoloading namespace (manually, or by using artisan app:name) for the classes in the app/ directory from App (the default) to Saveeo in composer.json:
"autoload": {
"psr-4": {
"Saveeo\\": "app/"
}
},
This is perfectly fine to do when we understand the implications. We can see the issue described in the question when we take a look at the project's folder structure for the file that causes the exception (with the namespaces in parentheses):
app (Saveeo)
├── Saveeo (Saveeo\Saveeo)
│ ├── Board (Saveeo\Saveeo\Board)
│ │ ├── Observers (Saveeo\Saveeo\Board\Observers)
│ │ │ ├── BoardEventListener
└── ...
For compatibility with PSR-4, the namespace for BoardEventListener should be Saveeo\Saveeo\Board\Observers because it exists in the Saveeo/ directory nested under app/. PSR-4 autoloading implementations resolve class files based on file names and paths, not the namespaces declared in the files. [Composer does read the namespace from the class files to create an optimized classmap, as long as the top-level namespace matches. See update.]
If we don't want to change the directory structure of the application, and we also don't want to use two Saveeos in the namespace, we can configure Composer to merge both directories into the same namespace when it autoloads classes:
"autoload": {
"psr-4": {
"Saveeo\\": [ "app/", "app/Saveeo/" ]
}
},
...and remember to composer dump-autoload.
It works, but I don't recommend this in practice. It deviates from the PSR-4 standard, makes the application susceptible to namespace conflicts, and may be confusing to other people working on the project. I suggest that you flatten the Saveeo namespace and directory, or choose a different namespace for the classes in the nested directory.
...things work just fine if I run composer dump-autoload -o but I am curious why would this throw an error when I run composer update...?
When generating the autoloading cache file, Composer doesn't actually execute your code. However, the artisan optimize command, which runs after composer update in most Laravel applications (until 5.5), does boot the application to perform its operations, so the problem code executes and we see the exception.
Update:
If using Saveeo\Board\etc was wrong versus doing Saveeo\Saveeo\Board\etc then other files around the entire application wouldn't work, but they do.
We can technically use non-PSR-4 namespaces that don't match the project's directory structure when we generate an optimized autoloader like we would to prepare an application for production:
composer dump-autoload --optimize
This works because Composer will scan each class file for namespaces to create a static classmap. When we don't specify --optimize, Composer relies on dynamic autoloading which matches file paths to namespaces, so non-standard namespaces or directory structures fail to resolve.
The namespacing for the project in question works for the most part, even though it doesn't follow PSR-4, because we're manually dumping an optimized autoloader by using the -o option for dump-autoload. However, we see the error message because composer update removes the cached classmap before running the update, so, by the time the artisan optimize command runs, the classmap no longer contains the classes that we dumped.
We can configure Composer to always optimize the autoloader by setting the optimize-autoloader configuration directive in composer.json:
"config": {
"optimize-autoloader": true
}
...which should fix the install and update commands for this project. It's a bit of a hack to get non-standard namespacing to resolve. With this approach, remember that we'll need to dump the autoloader whenever we add a new file in development that doesn't follow PSR-4.
This seems to be related to the Composer PSR autoloading. By default Laravel will include
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
which means "the root of the App namespace is in the app folder, and from there match namespace to folder structure".
Your Saveeo namespace hasn't been registered (it's not in the App hierarchy), so Composer doesn't know its location.
It should work if you add another line to your composer.json (and then dump-autoload)
"autoload": {
"psr-4": {
"App\\": "app/",
"Saveeo\\": "app/Saveeo"
}
}
Alternatively, you could, as the other answer points out, just place the whole Saveeo namespace within App (so it's App\Saveeo\Board\Observers\Events\BoardHasBeenCreated for instance). However your Saveeo namespace seems to be sort of a self-contained module, it may be more reasonable to have it as a separate namespace rather than renaming the namespace in all of its files.
I believe if you just change your namespace to:
App\Saveeo\Board\Observers instead of Saveeo\Board\Observers
all your problems should be solved. Please let me know if you have a reason for creating this new namespace, instead of just branching out from the base App namespace.
My profesionnal network block internet access. Some month ago I download the Silex framework from an archive (which contains composer.json file) and the composer.phar one's, then I transfer them on my desktop throught HDD.
My composer.json that I customized:
{
"name": "user/silex",
"require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
It works fine, my autoload customization too.
Today I want to add the monolog/monolog package, so I manually import it from an other computer.
I place it into my vendor folder, I add the following line to my composer.json file:
, "monolog/monolog": ">=1.0.0"
I run on the console:
php composer.phar dumpautoload
It outputs:
Generating autoload files
Then it stop without error, but the monolog namespace doesn't appear into my /vendor/composer/autoload_*.php files.
What did I miss?
Thanks to edmondscommerce's comment I found the solution:
I update my main composer.json file with an artifact respository (and I disable the packagist one):
{
"name": "user/silex",
"repositories": [
{
"type": "artifact",
"url": "artifact/"
}, {
"packagist": false
}
], "require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "monolog/monolog": "1.*"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
Then I put a folder called artifact according to the url put in the composer.json file.
I create into this folder a zip called monolog-monolog-1.8.zip with the library I want to add.
Then just launch a composer update command!
Be carefull, zip's root must contain a composer.json file, and this composer.json file must contain a version!
If you do not want to create a custom repository, you can also run composer install (or composer update) on a copy that is on a network-connected computer. Then you can copy over the newly added and extracted component into the vendor folder on the machine without internet access. Note that you also need to copy vendor/composer/installed.json to let composer know that the new package has been installed. Once you have copied all these files, you can run composer install on the machine without internet access and it will not try to install anything and dump autoload files.
I'm trying to organize my project with a base code and external bundles as a plugins for the base project.
I've already registered the bundles in packagist and the "composer.phar install" command works as expected. The autoloader also works as expected, so everything is OK but the "php console doctrine:generate:entities ACSACSPanelDynHostBundle" command don't work at all. It returns the next message:
[RuntimeException]
Can't find base path for "ACSACSPanelDynHostBundle" (path: "/var/www/acspanel/vendor/acs/paneldynhost", destination: "/var/www/acspanel/vendor/acs/paneldynhost").
I tryied to use psr-4 in composer.json to define the namespace but it don't works either.
I would like to know what is the proper way to use the console commands with my vendor bundles.
The code of my bundle composer.json is:
{
"name": "acs/paneldynhost",
"description": "Dynhost service creation for ACSPanel",
"keywords": ["dynamic domain","acspanel"],
"type": "
"autoload": {
"psr-4": { "ACS\\ACSPanelDynHostBundle\\": "" }
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
Background
I know what I'm trying to do sounds a bit wrong but I do have my reasons.
Basically I have a central core app that's a default laravel app with a few tweaks and boilerplate code, I have then developed a series of packages that can be used to extend the app through composer. These packages are not meant to function without the core framework so a dependency upon it is fully expected.
What I want to do
What I would like to do is have a BaseController in my core app and have the various controllers in my package extend this BaseController to provide universal functionality throughout the various module packages.
I was expecting to be able to place the base controller in app/controllers/BaseController.php
and then extend it from my package using:
class PackageController extends \BaseController{}
Unfortunately when I do this it still looks within the package (currently workbenched) for the controller and I get the error:
include(/var/www/l4core.dev/workbench/myvendor/mypackage/src/controllers/BaseController.php):
failed to open stream: No such file or directory
Can anyone tell me what I'm doing wrong here. I am looking for a solution which allows me to easily move my packages between vendor dir and workbench for development. Any help greatly appreciated
Update
The previously mentioned error message appears to have been due to an include in my packages /vendor/composer/classloader.php - I have now deleted the vendor directory and done a fresh composer install. This has not solved the problem but it has at least shifted it as I now get the following error message:
Class 'BaseController' not found
My Packages composer.json
{
"name": "modules/sesame",
"description": "",
"authors": [
{
"name": "any",
"email": ""
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.0.x",
"zizaco/confide": "dev-master",
"zizaco/entrust": "dev-master",
"conarwelsh/mustache-l4": "dev-master"
},
"autoload": {
"classmap": [
"src/controllers",
"src/models",
"src/migrations",
"src/seeds"
],
"psr-0": {
"Modules\\Sesame": "src/"
}
},
"minimum-stability": "dev"
}
Be sure to execute:
php artisan dump-autoload
And verify that your class BaseController is in /vendor/composer/autoload_classmap.php.
OR like the OP stated, removing the vendor directory and running composer install again could sometimes solve the problem.