I have written a shell script that works perfectly when I test it locally.
bin/cake myshell method
But when I assign it as a crob it's not working. Instead I see the default cake output:
Welcome to CakePHP v3.1.4 Console
---------------------------------------------------------------
App : src
Path: /home/fantastagram/public_html/src/
PHP : 5.6.16
---------------------------------------------------------------
Current Paths:
* app: src
* root: /home/fantastagram/public_html
* core: /home/fantastagram/public_html/vendor/cakephp/cakephp
Available Shells:
[Migrations] migrations
[CORE] i18n, orm_cache, plugin, routes, server
[app] console, instagram
To run an app or core command, type `cake shell_name [args]`
To run a plugin command, type `cake Plugin.shell_name [args]`
To get help on a specific command, type `cake shell_name --help`
Content-type: text/html; charset=UTF-8
It appears that the two arguments to the script are being ignored. I'm using the cron jobs tool in the cPanel...
What am I doing wrong?
I turned on debugging and found that the script was actually erroring out before it to my parameters. I googled the error and it turned out to be this: Cakephp 3 bin/cake bake - Undefined variable: argv
Tweaked the php.ini config and it worked perfectly.
Related
What I have:
WPKit/Module/AbstractFunctions.php Abstract Class;
wp-content/themes/mytheme/modules/quiz/Functions.php:
use WPKit\Module\AbstractFunctions;
class Functions extends AbstractFunctions { ... }
wp-content/themes/mytheme/tests/quiz/QuizFunctionsTest.php:
require_once dirname(__FILE__) . "/../../modules/quiz/Functions.php";
class QuizFunctionsTest extends TestCase {
public function testGetQuizByID() {
# some code
}
}
When running phpunit QuizFunctionsTest.php, it gives me the following error:
PHP Fatal error: Class '%path%\AbstractFunctions' not found in %path%/modules/quiz/Functions.php on line 18
I tried require_once the missing class but it didn't help. Outside the test class my code works just fine. Any thoughts?
TL;DR: It seems I couldn't get it to work because it was a WordPress setup so what I did was install PHPUnit via wget and use WP-CLI to scaffold theme-tests, then it worked like a charm.
First I installed the PHPUnit from terminal inside my theme directory:
wget -O phpunit https://phar.phpunit.de/phpunit-7.phar
chmod +x phpunit
Next I installed WP-CLI:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Next setting up the test suite:
wp scaffold theme-tests your-theme-slug
Also make sure you have svn installed.
In my case (and I found some mention it, too) I had to delete /tmp/wordpress and /tmp/wordpress-tests-lib and re-run the previous command twice because the script somehow didn't download everything.
Notice that you'll have a separate WordPress setup in /tmp/wordpress. In my primary WordPress setup I use WPKit library which is stored in WordPress root near wp-content so I had to copy it to /tmp/wordpress, otherwise my PHPUnit tests couldn't find WPKit files which were included in the classes I had to test.
So when you run wp scaffold it creates bin directory in your theme root. Run the following command from your theme root in order to install the test suite:
bin/install-wp-tests.sh <test-database-name> <user> <password> <host> <wordpress-version>
In my case it looked like:
bin/install-wp-tests.sh wp_test root '' localhost latest
Be sure to use empty database because running PHPUnit clears the database every time so you may lose your data.
After all these actions just run PHPUnit and you should be fine:
./phpunit
It runs tests in your-theme/tests directory. By default it ignores the default test file so use it to make your own simple tests to check everything works.
Whew.
Sources:
https://www.kirstencassidy.com/testing-wordpress-plugins-wp-cli-phpunit/
https://phpunit.de/getting-started/phpunit-7.html
https://wp-cli.org/#installing
https://www.smashingmagazine.com/2017/12/automated-testing-wordpress-plugins-phpunit/
If I navigate to this route with this slug (/client/example.com)
/**
* #Route("/client/{url}")
*/
I get this error
The requested resource "/client/example.com" was not found on this
server.
I'm using php built-in server php -S 127.0.0.1:8000 public/index.php
With this aproach it works but assets doesn't load properly
php -S localhost:8000 public/index.php
Edit:
without dot it works.
php bin/console router:match /client/example.com
[OK] Route "client_show" matches
php bin/console router:match /client/example
[OK] Route "client_show" matches
As Lawrence Cherone stated in the comments looks like it doesn't work with the built-in php server but it does work with the composer require server included in Symfony Recipes.
php bin/console server:run
I just updated to Yii 2.0.4 and now my custom console command is not working. However, the default Hello still works.
$ yii hello
hello world
$ yii kw
Error: Unknown command "kw".
$ ls commands
HelloController.php KWController.php
It was working immediately before in 2.0.3.
Strange because it shows up in yii command by itself:
$ yii | grep hello
- hello This command echoes the first argument that you have entered.
hello/index (default) This command echoes what you have entered as the message.
$ yii | grep kw
- kw
I am working on windows.
Problem is probably with the case of your controller name... the kw command would by default look for a KwController.php and won't find a KWController.php if your filesystem is case-sensitive.
You can fix that by either renaming the file, or if you don't want that, manually adding the controller file to the controllerMap in the yii file:
$application = new yii\console\Application($config);
$application->controllerMap['kw'] = 'console\controllers\KWController';
I am trying to create a controller in cakephp(1.3) using console. I am using windows XP and XAMPP.
My current cake console settings below
C:\xampp\htdocs\cake\apressblog\cake\console>cake
♀ Welcome to CakePHP v1.3.4 Console
--------------------------------------------------------------- Current Paths: -app: console
-working: C:\xampp\htdocs\cake\apressblog\cake\console
-root: C:\xampp\htdocs\cake\apressblog\cake
-core: C:\xampp\htdocs\cake\apressblog
Changing Paths: your working path
should be the same as your application
path to change your path use the
'-app' param. Example: -app
relative/path/to/myapp or -app
/absolute/path/to/myapp
Available Shells: acl [CORE]
i18n [CORE]
api [CORE]
schema [CORE]
bake [CORE]
testsuite [CORE]
console [CORE]
To run a command, type 'cake
shell_name [args]' To get help on a
specific command, type 'cake
shell_name help'
C:\xampp\htdocs\cake\apressblog\cake\console>-app
c:\xampp '-app' is not recognized as
an internal or external command,
operable program or batch file.
C:\xampp\htdocs\cake\apressblog\cake\console>
what are the path settings I need to set for creating a controller from console ?
I tried to change the app path but, when I type command cake It goes app directory to console,
Could you please help me to solve this issue
when I try to create a controller I am getting the following error :
C:\xampp\htdocs\cake\apressblog\cake\console>cake bake controller news
♀
Welcome to CakePHP v1.3.4 Console
---------------------------------------------------------------
App : console
Path: C:\xampp\htdocs\cake\apressblog\cake\console
---------------------------------------------------------------
Creating file C:\xampp\htdocs\cake\apressblog\cake\console\controllers\news_cont
roller.php
Wrote `C:\xampp\htdocs\cake\apressblog\cake\console\controllers\news_controller.
php`
You can download SimpleTest from http://simpletest.org
Bake is detecting possible fixtures..
Warning: include_once(C:\xampp\htdocs\cake\apressblog\cake\console\config\databa
se.php): failed to open stream: No such file or directory in C:\xampp\htdocs\cak
e\apressblog\cake\libs\model\connection_manager.php on line 23
Warning: include_once(): Failed opening 'C:\xampp\htdocs\cake\apressblog\cake\co
nsole\config\database.php' for inclusion (include_path='.;\xampp\php\PEAR') in C
:\xampp\htdocs\cake\apressblog\cake\libs\model\connection_manager.php on line 23
Fatal error: ConnectionManager::getDataSource - Non-existent data source default
in C:\xampp\htdocs\cake\apressblog\cake\libs\model\connection_manager.php on li
ne 102
C:\xampp\htdocs\cake\apressblog\cake\console>
You need to create your database.php file in the config folder so that Cake knows what database to connect to for the models.
Once you have done this you need to create your database schema and then bake the model for it.
I'd been having the same problem and was googling when I stumbled upon this. I was getting the same 'Warning: include_once...' error as you did.
I figured out this was happening only when I ran the 'cake bake' command from the ..\cake\console\ folder like you did.
So here's what fixed this issue for me. I added path to the console folder to my environment variables. Now I could call the cake bake command from anywhere.
Then I changed directory to your app folder e.g. ...\htdocs\myCakeWebsite\app
Then run 'cake bake' command! It worked fine from then on.
sources: http://www.youtube.com/watch?v=xvJH0wTlRg
I am trying to create a controller in cakephp(1.3) using console. I am using windows XP and XAMPP.
My current cake console settings below
C:\xampp\htdocs\cake\apressblog\cake\console>cake
♀ Welcome to CakePHP v1.3.4 Console
--------------------------------------------------------------- Current Paths: -app: console
-working: C:\xampp\htdocs\cake\apressblog\cake\console
-root: C:\xampp\htdocs\cake\apressblog\cake
-core: C:\xampp\htdocs\cake\apressblog
Changing Paths: your working path
should be the same as your application
path to change your path use the
'-app' param. Example: -app
relative/path/to/myapp or -app
/absolute/path/to/myapp
Available Shells: acl [CORE]
i18n [CORE]
api [CORE]
schema [CORE]
bake [CORE]
testsuite [CORE]
console [CORE]
To run a command, type 'cake
shell_name [args]' To get help on a
specific command, type 'cake
shell_name help'
C:\xampp\htdocs\cake\apressblog\cake\console>-app
c:\xampp '-app' is not recognized as
an internal or external command,
operable program or batch file.
C:\xampp\htdocs\cake\apressblog\cake\console>
what are the path settings I need to set for creating a controller from console ?
I tried to change the app path but, when I type command cake It goes app directory to console,
-app is a parameter for the cake command:
C:\...\console>cake -app C:\xampp\htdocs\cake\apressblog\app
You can also run cake console without problems, provided you're at the correct path. Try the following:
C:\xampp\htdocs\cake\apressblog\>C:\xampp\htdocs\cake\apressblog\cake\console\cake
or, to save yourself the trouble, add C:\xampp\htdocs\cake\apressblog\cake\console to the %PATH% environmental variable.