I'm trying to get PHPUnit working; I haven't used it before. If I run phpunit in the CLI, it works, but via a script (which is what I'm looking for) it doesn't. This is the output I get (note the two spaces after Class):
Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in /usr/local/share/pear/PHPUnit/Util/Test.php:295
Stack trace:
#0 /usr/local/share/pear/PHPUnit/Util/Test.php(295): ReflectionClass->__construct('')
#1 /usr/local/share/pear/PHPUnit/Util/Test.php(576): PHPUnit_Util_Test::parseTestMethodAnnotations(false, false)
#2 /usr/local/share/pear/PHPUnit/Util/Test.php(350): PHPUnit_Util_Test::getBooleanAnnotationSetting(false, false, 'backupGlobals')
#3 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(458): PHPUnit_Util_Test::getBackupSettings(false, false)
#4 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(834): PHPUnit_Framework_TestSuite::createTest(Object(ReflectionClass), false)
#5 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(212): PHPUnit_Framework_TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#6 /usr/local/share/pear/PHPUnit/Framework/TestSuite.php(315): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#7 /var/www/www.s in /usr/local/share/pear/PHPUnit/Util/Test.php on line 295
It appears that the class name is being lost in addTestMethod. This is my code:
<?php
require_once 'PHPUnit/Autoload.php';
class MyTestCase extends PHPUnit_Framework_TestCase {
public function testSubtraction() {
$this->assertEquals(2 - 2, 0);
}
public function testAddition() {
$this->assertEquals(2 + 2, 4);
}
}
$c = new MyTestCase();
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTestSuite('MyTestCase');
PHPUnit_TextUI_TestRunner::run($suite);
Am I setting things up wrong?
Here are the versions:
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
File_Iterator 1.3.3 stable
PHPUnit 3.7.21 stable
PHPUnit_MockObject 1.2.3 stable
PHP_CodeCoverage 1.2.11 stable
PHP_Timer 1.0.4 stable
PHP_TokenStream 1.1.5 stable
Text_Template 1.1.4 stable
PHP 5.4
Reflection does work, I use that in my own scripts. Hopefully it's something with my setup, I really don't want to have to modify PHPUnit...surely it works elsewhere.
Something is wrong:
'Class does not exist'
^
`- normally the classname is given here
As you can see your error message is either missing something or PHPUnit tried to create a testcase out of nothing. Check you don't have some superfluous / incomplete files in your tests folder. Or something like that along the line. It's just a guess based on the error message, if I were you I would tackle this down in a debug session to actually find out what happens. This includes remove-debugging the testing session and stepping through and probably adding debug code into the phpunit install. Take care and backups.
Related
I've installed Phalcon and trying to create new project: phalcon project store. But instead of this I get these errors:
PHP Fatal error: Uncaught Error: Class "Phalcon\Config" not found in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php:48
Stack trace:
#0 C:\Composer\vendor\phalcon\devtools\src\Commands\Builtin\Project.php(74): Phalcon\DevTools\Builder\Component\AbstractComponent->__construct(Array)
#1 C:\Composer\vendor\phalcon\devtools\src\Script.php(109): Phalcon\DevTools\Commands\Builtin\Project->run(Array)
#2 C:\Composer\vendor\phalcon\devtools\src\Script.php(148): Phalcon\DevTools\Script->dispatch(Object(Phalcon\DevTools\Commands\Builtin\Project))
#3 C:\Composer\vendor\phalcon\devtools\phalcon(65): Phalcon\DevTools\Script->run()
#4 {main}
thrown in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php on line 48
Fatal error: Uncaught Error: Class "Phalcon\Config" not found in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php:48
Stack trace:
#0 C:\Composer\vendor\phalcon\devtools\src\Commands\Builtin\Project.php(74): Phalcon\DevTools\Builder\Component\AbstractComponent->__construct(Array)
#1 C:\Composer\vendor\phalcon\devtools\src\Script.php(109): Phalcon\DevTools\Commands\Builtin\Project->run(Array)
#2 C:\Composer\vendor\phalcon\devtools\src\Script.php(148): Phalcon\DevTools\Script->dispatch(Object(Phalcon\DevTools\Commands\Builtin\Project))
#3 C:\Composer\vendor\phalcon\devtools\phalcon(65): Phalcon\DevTools\Script->run()
#4 {main}
thrown in C:\Composer\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php on line 48
My PHP version is 8.0.8 Thread Safe x64, I've installed PSR extension and Phalcon 5.0.0 from here: https://github.com/phalcon/cphalcon/releases/tag/v5.0.0beta3, file phalcon-php8.0-ts-windows2019-vs16-x64.zip, that means I have compatible version of framework. phalcon.bat was added to environment variables. What's the problem?
Usually this error occurs when the extension is not loaded by php, see with phpinfo(), also run the componser install insider phalcon-devtools, but probably it is the php not loading the phalcon extension or PHP is not in the windows PATH , also check if the php-fpm log does not contain any extension loading errors, test in cmd the command php -v
also create a index.php and try it
<?php
use Phalcon\Mvc\Micro;
$app = new Micro();
$app->get('/', function () { echo "<h1>test</h1>";});
$app->handle();
Try do the following Go to Edit The system environment variables -> system variables -> path -> edit add phalcon.bat folder path testing here i used C:\Users\renato\Downloads\phalcon-devtools-4.2.0\phalcon-devtools-4.2.0 ( just path folder where the .sh/.bat it is, do not include the file and extension) and worked fine with php 8.0.16 windows 10 phalcon 5
and then go to the power shell and input phalcon
https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
Do not forget to run composer install inside phalcon devtools folder.
also on powershell input php -m to see the loaded modules and if it has an error
I'm trying to run this simple code on both PHP 7 and 8:
$loop = \React\EventLoop\Factory::create();
$filesystem = \React\Filesystem\Filesystem::create($loop);
$file = $filesystem->file('test.txt');
$file->getContents()->then(function ($contents) {
echo $contents . PHP_EOL;
});
$loop->run();
After installing via composer, and yet it tells me that adapter is missing
Error:
PHP Fatal error: Uncaught RuntimeException: No supported adapter found for this installation in \root\src\Filesystem.php:31
Stack trace:
#0 \root\try.php(6): React\Filesystem\Filesystem::create()
#1 {main}
thrown in \root\vendor\react\filesystem\src\Filesystem.php on line 31
Just look where and why the exception originated. (I will use react/filesystem:0.1.2 in code examples.)
The exception was thrown in React\Filesystem\Filesystem::create(). List of supported adapters is obtained from React\Filesystem\Filesystem::getSupportedAdapters().
This way you will come to methods which define whether given adapter is available on your platform:
Method Eio\Adapter::isSupported():
return substr(strtolower(PHP_OS), 0, 3) !== 'win' && function_exists('proc_open');
This means your platform must not be Windows and proc_open() function must exist (i.e. it must not be disabled for security reasons by disable_functions directive).
Method ChildProcess\Adapter::isSupported():
return extension_loaded('eio');
This means eio PHP extension must be installed, see installation instructions.
For me it also does not work as I am on Windows. For development with ReactPHP, it is generally a good idea to run PHP on Linux virtual machine for better compatibility.
I am working through upgrading my PHP 5.4, Laravel 4.2 application to PHP 7.4, Laravel 5.8.
In some of my tests, on tearDownAfterClass, I will do some DB cleanup. With Laravel 5.8, these don't work and I can't figure out why.
The following test using Laravel 5.4, works. With 5.8, does not work.
I have updated my 5.8 configs from the defaults, they are proper.
My database connection works, the tests all pass with DB activity.
The error only fails in the static tearDownAfterClass, I added the same \DB::table(static::$audittable)->truncate(); to one of my tests, it works without error.
How do I fix the exception below?
Using PHP 7.4.6, Laravel 5.8:
class ModelAuditQueriesTest extends TestCase
{
static $audittable = 'contactnotesaudit';
public static function tearDownAfterClass()
{
\DB::table(static::$audittable)->truncate(); **// <-- this fails, error below; line 11**
parent::tearDownAfterClass();
}
public function testInsertSingle()
{
\DB::table(static::$audittable)->truncate(); **// <-- this works, no errors**
/**
* testing stuff with models that insert and select with database, successfully
*/
}
}
With PHPUNIT.XML, processIsolation = false
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php:960
Stack trace:
#0 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(794): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(170): Illuminate\Foundation\Application->make('Illuminate\\ in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 960
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php:960
Stack trace:
#0 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(794): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(170): Illuminate\Foundation\Application->make('Illuminate\\ in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 960
With PHPUNIT.XML, processIsolation = true
PHP Fatal error: Uncaught Error: Class 'DB' not found in C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php:11
Stack trace:
#0 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\Framework\TestSuite.php(760): Tests\commonmodelaudit\ModelAuditQueriesTest::tearDownAfterClass()
#1 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(545): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#2 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\Command.php(195): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#3 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#4 C:\CODE\IDWEB5\vendor\phpunit\phpunit\phpunit(53): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php on line 11
Error : Cannot use object of type Illuminate\Support\Facades\Config as array
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:270
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:101
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:77
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:349
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:239
C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php:11
I have run the following to make sure all is clean:
composer dump-autoload
php artisan clear-compiled
php artisan optimize
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
I think the application has already shut down at the tearDownAfterClass part of the code.
Since you are trying to truncate a table, I think you might find it easier to instead use the trait DatabaseTransactions e.g.
class ModelAuditQueriesTest extends TestCase
{
use DatabaseTransactions;
}
this will make any changes you make in the database during this test not be rolled back since they are all done within a transaction which is never committed.
Another hacky way to do what you want is to "restart" the application.
The TestCase that comes in the boilerplate has a trait CreatesApplication. This unfortunately is not static but you can just copy-paste it and "restart" the application:
class ModelAuditQueriesTest extends TestCase
{
static $audittable = 'contactnotesaudit';
public static function tearDownAfterClass()
{
$app = require __DIR__.'/../bootstrap/app.php'; //You might need to adjust the path
$app->make(Kernel::class)->bootstrap();
\DB::table(static::$audittable)->truncate();
parent::tearDownAfterClass();
}
}
Now unfortunately the error you are seeing is that the error handler could not be instantiated which means once you do this you will see the actual reason that the error handler was being instantiated which is probably going to be another exception. However, at least that might be more informative.
I have installed magento2 in my linux centos7. After installing magento2 successfully while accessing the web page is getting following error with empty content.
{{menuState.title}}
PHP version:7.1.3
OS: centos7
And the PHP-fpm error log has following error.
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Zend_Controller_Plugin_Abstract::setResponse() must be an instance of Zend_Controller_Response_Abstract, instance of Magento\Framework\HTTP\PhpEnvironment\Response given, called in /var/www/magento2/lib/internal/Magento/Framework/Profiler/Driver/Standard/Output/Firebug.php on line 61 and defined in /var/www/magento2/vendor/magento/zendframework1/library/Zend/Controller/Plugin/Abstract.php:70
Stack trace:
#0 /var/www/magento2/lib/internal/Magento/Framework/Profiler/Driver/Standard/Output/Firebug.php(61): Zend_Controller_Plugin_Abstract->setResponse(Object(Magento\Framework\HTTP\PhpEnvironment\Response))
#1 /var/www/magento2/lib/internal/Magento/Framework/Profiler/Driver/Standard.php(195): Magento\Framework\Profiler\Driver\Standard\Output\Firebug->display(Object(Magento\Framework\Profiler\Driver\Standard\Stat))
#2 [internal function]: Magento\Framework\Profiler\Driver\Standard->display()
#3 {main}
thrown in /var/www/magento2/vendor/magento/zendframework1/library/Zend/Controller/Plugin/Abstract.php on line 70
How can I resolve this error?
This was a Magento Bug reported ...
But it's already been ...
https://github.com/magento/magento2/issues/7068
So, come on ...
Did you update the magento? What is the current version?
I found this information at the base of Magento: https://devdocs.magento.com/guides/v2.3/config-guide/bootstrap/mage-profiler.html
You have this option ...
The temporary fix is install symfony / yaml from dev branch and then our module:
composer require symfony/yaml: dev-issue-814
composer require mirasvit/module-profiler
Try using / installing php7.2
See this Magento Project reference >>>
https://magento.stackexchange.com/questions/49000/magento-2-is-there-a-profiler
Be sure to back up before the above procedures ...
Since I don't know the correct version of your current Magento, I looked for alternatives to fix.
I hope it helps you ...
Good luck! Send news about your progress ...
I just took a project from a couple of months ago which was made in Laravel. This project also utilizes Laravel Voyager - the admin panel package.
After browsing to http://example.com/admin, I got this weird error which came out of nowhere and I'm also unsure how to debug it. It looks like this:
Fatal error: Cannot declare class Symfony\Component\HttpFoundation\AcceptHeader, because the name is already in use in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php on line 22
Fatal error: Uncaught Error: Class 'Symfony\Component\HttpFoundation\AcceptHeaderItem' not found in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php:61 Stack trace: #0 [internal function]: Symfony\Component\HttpFoundation\AcceptHeader::Symfony\Component\HttpFoundation\{closure}(Array) #1 /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php(57): array_map(Object(Closure), Array) #2 /c/Users/User/Code/example-website/vendor/symfony/http-foundation/Request.php(1664): Symfony\Component\HttpFoundation\AcceptHeader::fromString('text/html,appli...') #3 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(54): Symfony\Component\HttpFoundation\Request->getAcceptableContentTypes() #4 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(44): Illuminate\Http\Request->wantsJson() #5 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illumina in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php on line 61
This error is very expected and I've never seen it before in my project (or anywhere else for that matter).
How can I debug this issue?
As a sanity check, delete the vendor directory and then run composer install to re-fetch your dependencies and see if the error is resolved. If not, then attempt composer update to fetch the latest versions of your dependencies in which this issue may have been resolved.