I tried to run a PHP file (of cakePHP) by the following
$ /bin/sh /var/www/html/app/Console/cake HumanResource UpdateData
But there is an error occur:
PHP Fatal error: Class 'Inflector' not found in /var/www/html/app/lib/Cake/Console/ShellDispatcher.php on line 209
Some information in my server:
Centos: 6.5
PHP: 5.3
Httpd: 2.2.15
CakePHP version: 2.1.3
Please help me to fix it. Thanks
You forgot add:
use Cake\Utility\Inflector;
Example:
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Utility\Inflector;
class CamerasShell extends Shell {
public function main() {
$this->out(Inflector::slug('Please Generate Me Slug', '-'));
}
}
Related
This question already has answers here:
Fatal error: Class 'ZipArchive' not found in
(25 answers)
Closed 3 months ago.
I have a problem when I execute following command.
php artisan db:seed --class=QuestionTableSeeder
The error message is as follows.
Symfony\Component\Debug\Exception\FatalThrowableError : Class
'ZipArchive' not found
at
/var/www/csi/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:338
334| $excel->removeCellXfByIndex(0); // remove the default style
335| }
336| $unparsedLoadedData = [];
337|
338| $zip = new ZipArchive();
339| $zip->open($pFilename);
340|
341| // Read the theme first, because we need the colour scheme when reading the styles
342| //~ http://schemas.openxmlformats.org/package/2006/relationships"
Exception trace:
1
PhpOffice\PhpSpreadsheet\Reader\Xlsx::load("/tmp/laravel-excel-8wjCLq8hS4qVk49C5Rg30jkE6zVErU01.xlsx")
/var/www/csi/vendor/maatwebsite/excel/src/Reader.php:229
2 Maatwebsite\Excel\Reader::readSpreadsheet()
/var/www/csi/vendor/maatwebsite/excel/src/Reader.php:215
Please use the argument -v to see more details.
The class QuestionTableSeeder is following.
<?php
use App\Imports\QuestionImport;
use App\ORM\Question;
use Illuminate\Database\Seeder;
use Maatwebsite\Excel\Facades\Excel;
class QuestionTableSeeder extends Seeder
{
public function run(): void
{
DB::statement('set foreign_key_checks=0');
Question::truncate();
DB::statement('set foreign_key_checks=1');
Excel::import(new QuestionImport(), 'database/seeds/data/questions.xlsx');
}
}
Please tell me the solution. What should I do to resolve the problem? I have installed php7.3-zip and php73-php-pecl-zip, then also restarted Apache but still it doesn't work.
The versions are following;
PHP : 7.3
Laravel : 6.6.0
maatwebsite/excel : 3.1.17
mysql Ver 15.1 : Distrib 5.5.64-MariaDB, for Linux (x86_64) using readline 5.1
CentOS Linux : release 7.7.1908 (Core)
Try to run
php -m | grep zip
If missing the "zip" show on output CLI that means you don't installed php zip extension. You should be install.
yum install -y zip php-zip php-pecl-zip
Hope that helps.
When I try to run PHPUnit in Netbeans I face this error:
Fatal error: Class 'PHPUnit_Framework_TestSuite' not found in C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\NetBeansSuite.php on line 63
Done.
This happens both in Netbeans and CLI.
I started debugging this problem by navigating to this directory: C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\.
That directory contained one file: NetBeansSuite.php. I opened it to look for clues, and saw this line:
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
What I didn't see is any concrete PHPUnit_Framework_TestSuite class.
What's next is that the NetBeansSuite.php file doesn't have any include or require language constructs that may include the PHPUnit_Framework_TestSuite class.
So, in order to fix the fatal error problem I should include the PHPUnit_Framework_TestSuite in NetbeansSuite.php.
This is a problem because I'm not the author of NetbeansSuite.php.
On top of that the author of NetbeansSuite.php wrote this in the comment section:
<b>WARNING: User changes to this file should be avoided.</b>
I read further in the comments:
* Copyright 2010 Oracle and/or its affiliates. All rights reserved.
I guess the NetbeansSuite.php file is outdated.
Searching on the net brought me to this stackoverflow question:
Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?
They claim that using a namespaced version of PHPUnit_Framework_TestCase should fix the problem. So I did what they wrote.
I stubbornly changed NetBeansSuite.php.
Old code:
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
New code:
require_once 'PHPUnit/Autoload.php';
use PHPUnit\Framework\TestCase;
class NetBeansSuite extends TestCase {
I tried to run the test case again, and this was the unfortunately result:
Fatal error: Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in C:\wamp64\www\test\CalculatorTest.php on line 97
In other words, it gave me a new problem.
My system:
Windows 10
WAMP
php 7.2.14
PHPUnit 8.0.6
Netbeans version 8.2 (Netbeans PHPUnit plugin installed through Tools > Plugins. Version: 0.26.2)
My question is: does anybody know how the NetBeansSuite.php file should be like with the system described above?
The setUp method in my test case:
protected function setUp()
{
$this->object = new Calculator;
}
Update: The Skeleton Generator project is abandoned.
See link: https://github.com/sebastianbergmann/phpunit-skeleton-generator
So in order to fix the Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp() error the corresponding return type declaration should be used in the test case.
// I added : void
protected function setUp(): void
{
$this->object = new Calculator;
}
// : void needs to be added in the tearDown method as well
protected function tearDown(): void
Unfortunately, this gave me new problems:
Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in C:\wamp64\www\test\CalculatorTest.php on line 4
Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.;C:\php\pear') in C:\wamp64\www\test\CalculatorTest.php on line 4
I solved this by manually installing PEAR and creating a new "PHPUnit" directory in C:\php\PEAR. Then I created a new Autoload.php file. I filled the content of Autoload.php with a PSR-4 example file found at: https://www.php-fig.org/psr/psr-4/.
This solved the Autoload problem, but I faced a new problem during the execution of a test case.
C:\wamp64\www\test>phpunit CalculatorTest.php
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.
Time: 170 ms, Memory: 10.00 MB
No tests executed!
It shows No tests executed! but I have 5 tests.
I'll make a new question for this.
Here it is: PHPUnit 8 installed on Windows through PHAR shows No tests are executed
Initially indeed you should update your namespaces since it has been changed in more recent versions of PHPUnit.
The error however indicates that your CalculatorTest::setUp() method is not compatible with the PHPUnit version. Could you maybe post that method here?
For the same issue, I directly changed the file "NetBeansSuite.php" (C:\Users\USERNAME\AppData\Roaming\NetBeans\8.2\phpunit) as following :
class NetBeansSuite extends \PHPUnit\Framework\TestSuite {
After that, CLI and Netbeans was working.
On running this test, I get Error: Call to undefined method OrderControllerTest::request()
<?php
use PHPUnit\Framework\TestCase;
class OrderControllerTest extends TestCase
{
public function testupload() {
$a='foo';
$output = $this->request('POST',['Order', 'upload',$a] );
}
}
PHPUNIT Version: 7.2.4. Appreciate any help
For the kenjis/ci-phpunit-test package if you run phpunit from the application/tests folder so it picks up on the included phpunit.xml and included TestCase Class then they should run.
cd application/tests
then, if you are using the composer installed version of phpunit in your project:
../../vendor/bin/phpunit
or if you're using the globally (apt etc.) installed version simply:
phpunit
see http://blog.a-way-out.net/blog/2015/06/12/codeigniter3-phpunit/#how-to-run-tests
The package kenjis/ci-phpunit-test extends the standard PHPUnit package so what you need to do is to extend the CIPHPUnitTestCase instead like in example below.
<?php
class OrderControllerTest extends CIPHPUnitTestCase
{
public function testupload() {
$a='foo';
$output = $this->request('POST',['Order', 'upload',$a] );
}
}
You may need to configure your IDE so that it can find CIPHPUnitTestCase class.
I am using Eclipse pdt for PHP Developers Version: Oxygen.2 Release (4.7.2).
I created a Composer Project and I added those dependencies:
then I created a TestCase file to test my class.
I could not change the superclass "PHPUnit_Framework_TestCase".
I got this warning when creating the TestCase file
There is no element 'PHPUnit_Framework_TestCase' in the project
'PayementAPI'
then into the default TestCase Class created I changed the extends "PHPUnit_Framework_TestCase" to "TestCase" and I added the import.
<?php
use PHPUnit\Framework\TestCase;
include 'otherClass.php';
/**
* MyClass1 test case.
*/
class MyClass1Test extends TestCase
{
...
}
Then I tried to run my class test as PHPUnit test but got this error:
PHP Fatal error: Declaration of PHPUnitLogger::flush() must be compatible with PHPUnit\Util\Printer::flush(): void in C:\Users\User\AppData\Local\Temp\phpunit_printer\PHPUnitLogger.php on line 33
Try one with a lower version of phpunit.phar, download the lower version here.
I am using Composer with CodeIgniter in a Vagrant machine. My development environment is CentOS 6.5, PHP 5.6. I've loaded my other package from github through composer.json and in my development environment everything working fine. When I loaded the full folder in my DigitalOcean VPS and try to run the application, I got this fatal error:
Fatal error: Class 'AppioLab\LRPC\Lrpc' not found in /var/www/html/personal/demo/lstoxero/public_html/application/controllers/mytest.php on line 43
Line 43 is where I am trying to create an instance of Class I've loaded through composer and autoload.php
This is my folder structure
This is my Test Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use AppioLab\LRPC\Lrpc;
error_reporting(E_ALL);
ini_set('display_errors', 1);
class MyTest extends CI_Controller {
public function test(){
echo "Cron Test<br>";
$lrpc = new Lrpc(); // this is line 43 in my code.
echo "lrpc loadedt<br>";
}
}
When I try to access this test function with url http://mydemosite.com/MyTest/test I get the error I mention above. What I am doing wrong and why is it running in Vagrant but not in live which is also CentOS 6.5?