I'm using phpunit for testing in a magento's project.
The issues is that I got this directory inside magento:
magento/
-tests/
--integration/bootstrap.php
---Training/
----Example/
-----Helper/DataTest.php
So, I got a bootstrap.php, inside this file I turn off warnings for my testing:
require_once __DIR__ . '/../../app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
$handler = set_error_handler(function () {});
set_error_handler(function ($errno, $errstr, $errfile, $errline) use ($handler)
{
if (E_WARNING === $errno
&& 0 === strpos($errstr, 'include(')
&& substr($errfile, -19) == 'Varien/Autoload.php'
) {
return null;
}
return call_user_func($handler, $errno, $errstr, $errfile, $errline);
});
If this code is inside of DataTest.php inside the function setUpBeforeClass(), everything is ok, but when I create bootstrap.php and execute in console:
phpunit --bootstrap tests/integration/bootstrap.php tests/integration/
I got the following answer:
Fatal error: Uncaught exception 'Exception' with message 'Warning: include(PHPUnit\Extensions\Story\TestCase.php): failed to open stream: No such file or directory in C:\wamp\www\magento\lib\Varien\Autoload.php on line 94' in C:\wamp\www\magento\app\code\core\Mage\Core\functions.php on line 245
Exception: Warning: include(PHPUnit\Extensions\Story\TestCase.php): failed to open stream: No such file or directory in C:\wamp\www\magento\lib\Varien\Autoload.php on line 94 in C:\wamp\www\magento\app\code\core\Mage\Core\functions.php on line 245
I got phpunit in my local server in bin\php\php5.5.12 (in Windows) and I can access in any directory.
So, I don't understand what's going on... because I do not need to modify the core of magento to disable warnings.
Someone can help me to understand?
Thanks for all!!
:)
Your autoloader is trying to load classes it is not responsible for.
Related
I'm trying to find a way to check if an error has been written to the console when running a cypress unit test.
I know how to log something to the console
cy.log('log this to the console');
but not how to check if an error has been written to it.
any suggestions how to read errors from the (browser) console log?
note: probably not the "smart" way to test but sometimes my js libraries which I use would "complain" and write the errors to the browser log. this is to simplify testing.
This does exactly what I needed of catching any error in the console and do an assertion of the logs count. Just add the following in cypress/support/index.js
Cypress.on('window:before:load', (win) => {
cy.spy(win.console, 'error');
cy.spy(win.console, 'warn');
});
afterEach(() => {
cy.window().then((win) => {
expect(win.console.error).to.have.callCount(0);
expect(win.console.warn).to.have.callCount(0);
});
});
There have been some updates since the previous answers.
Because the window is re-created with each cy.visit, Cypress recommends stubbing as a part of the cy.visit command.
cy.visit('/', {
onBeforeLoad(win) {
cy.stub(win.console, 'log').as('consoleLog')
cy.stub(win.console, 'error').as('consoleError')
}
})
//...
cy.get('#consoleLog').should('be.calledWith', 'Hello World!')
cy.get('#consoleError').should('be.calledOnce')
For more details see the official FAQ for stubbing out the console: https://docs.cypress.io/faq/questions/using-cypress-faq.html#How-do-I-spy-on-console-log
And the recipe repository: https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/stubbing-spying__console
Edit: the following does not directly log to terminal when in headless mode, but it nonetheless fails the test on AUT's console.error and displays the error message indirectly, even in the headless terminal, which may be what you want.
I'm not sure exactly what you mean, but let's go through all the places where an output can be logged in cypress, and how to handle several cases.
First, an overview:
To log into the command log, you use:
// from inside your test
cy.log('foo');
To log into devTools console:
// from inside your test
console.log('bar');
To log into terminal, you need to log from within the Cypress' node process:
// from within e.g. your plugin/index.js file
console.log('baz');
How to log AUT's errors to Terminal, Command Log, and fail the test
(note, AUT here stands for Application under test, meaning your application).
I'm also using ansicolor package to make the error red-colored in the terminal, which is optional.
// plugins/index.js
const ansi = require(`ansicolor`);
module.exports = ( on ) => {
on(`task`, {
error ( message ) {
// write the error in red color
console.error( ansi.red(message) );
// play `beep` sound for extra purchase
process.stdout.write(`\u0007`);
return null;
}
});
};
Note: using internal cy.now() command to work around Cypress' tendency to throw Cypress detected that you returned a promise when it (IMO) shouldn't.
(adapted from https://github.com/cypress-io/cypress/issues/300#issuecomment-438176246)
// support/index.js or your test file
Cypress.on(`window:before:load`, win => {
cy.stub( win.console, `error`, msg => {
// log to Terminal
cy.now(`task`, `error`, msg );
// log to Command Log & fail the test
throw new Error( msg );
});
});
Currently there is no straightforward way to do what you are asking but there have been some good discussions on how best to get this information. I copied one solution here but if you follow the github link you can see other solutions proposed.
This snippet was taken from the github issue found here: https://github.com/cypress-io/cypress/issues/300
Just FYI the one easy solution is just to spy on console functions.
cy.window().then((win) => { cy.spy(win.console, "log") })
That will print a command log every time that function is called, and
you could also then assert what has been logged.
Another option depending on why you want to assert that something went wrong is to print the error out under the tests in headless mode. The VP of engineering created an NPM package that does this for you.
Cypress-failed-log
The most easiest way if you simply want to ensure that no error is in the console (which is the most usecase I assume).
# npm
npm install cypress-fail-on-console-error --save-dev
# yarn
yarn add cypress-fail-on-console-error -D
And then add to your support/index.ts file:
import failOnConsoleError from "cypress-fail-on-console-error"
failOnConsoleError()
Now your cypress tests are failing just in time when a console error is printed.
This is the working solution I currently use to check for console errors.
let windowConsoleError;
Cypress.on('window:before:load', (win) => {
windowConsoleError = cy.spy(win.console, 'error');
})
afterEach(() => {
expect(windowConsoleError).to.not.be.called;
})
I am trying to extend module-ui/base/web/js/form/element/select.js
I have created a module, added requirejs-config.js and copied select.js by creating same file path as it in vendor.
After setup:upgrade and setup:static-content:deploy, I get error saying
"Uncaught Error: Script error for:
Thelist_Customjs/js/form/element/abstract"
My requirejs-config.js file code is as follows
var config = {
map: {
'*': {
'Magento_Ui/js/form/element/select':'Thelist_Customjs/js/form/element/select'
}
}
};
You need to also copy the file from
vendor\magento\module-ui\view\base\web\js\form\element\abstract.js
to
Thelist_Customjs/js/form/element/abstract.js
Becasue in select.js that file is used.
I am getting the error on my home page. i don't what the issue is .. request support on the same. tried all steps . searching for an answer.atal error: Call to undefined method Mage::helper() in /home/primasource/public_html/includes/src/Mage_Core_Model_Resource_Setup.php on line 308
Try to compile it again,
go to your admin painel > System menu -> Tools > Compiler > Run Process of compilation or Disable
This should do the trick.
Sounds like you're dealing with a significantly hacked system -- in a standard system the static Mage::helper method is defined in
#File: app/Mage.php
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
If your system can't find this, it means someone has edited your core app/Mage.php to remove this method, someone has removed the Mage class, or someone has changed your system to use a different Mage class. Start debugging there, and good luck!
I've been trying to pick my way through this error but I feel like I'm getting nowhere.
We're in the process of migrating a website from one server to another. All pages seem to work on the new site except for the contact form pages which appear to be trying to use 'form_helper.php'. These pages work correctly on the old server but not on the new one. I get an error of:
Fatal error: Call to undefined method CI_Loader::is_loaded() in C:\DATA\XXXX.com\www\application\helpers\form_helper.php on line 1038
Line 1038 of form_helper.php has the following on it:
if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
Any ideas would be GREATLY appreciated as I'm not that familiar with CodeIgniter.
Thanks in advance...
EDIT:
So I've worked out how to seemingly fix it... If I comment out the following code in the form_helper file, the page loads with no error:
/*if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
{
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
return $return;
}
return $CI->$object;
}*/
Is this a bad idea? The full function now looks like this:
if ( ! function_exists('_get_validation_object'))
{
function &_get_validation_object()
{
$CI =& get_instance();
// We set this as a variable since we're returning by reference.
$return = FALSE;
/*if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
{
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
return $return;
}
return $CI->$object;
}*/
return $return;
}
}
Make sure you have moved any array values in application/config/autoload.php from $autoload[‘plugins’] to $autoload[‘helpers’] or you will notice stuff break.
is_loaded() function is defined in Code/common.php Make sure the function is in right place.
I have a new installation of Laravel on a machine running ubuntu 12.04 LTS, Nginx, php-cgi, and Laravel v3.2.14
I am getting the following error.
Unhandled Exception
Message:
Undefined index: argv
Location:
DOCUMNET ROOT/laravel/core.php on line 218
EDIT:
I have managed to get a slightly more descriptive error by commenting out the error handling function in laravel //Error::shutdown(); on line 50 of DOCUMENT ROOT/laravel/laravel.php
Note that this line does not cause the error, it only seems to register a handler for the code that does.
Here is the error:
Unhandled Exception
Message:
A driver must be set before using the session.
Location:
DOCUMENT ROOT/laravel/session.php on line 109
Stack Trace:
DOCUMENT ROOT/laravel/session.php(150): Laravel\Session::instance()
DOCUMENT ROOT/laravel/laravel.php(195):
Laravel\Session::__callStatic('save', Array)
DOCUMENT ROOT/laravel/laravel.php(195): Laravel\Session::save()
DOCUMENT ROOT/public/index.php(34): require('/mona/developme...')
{main}
These are the code blocks causing the error:
if (Config::get('session.driver') !== '')
{
Session::save();
}
Which calls this function in DOCUMENT ROOT/laravel/session.php
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(static::instance(), $method), $parameters);
}
$method contains the string 'save', and $parameters is an empty array.
Laravel thinks that it is being accessed by cli if you are using php-cgi.
The solution is Modifying DOCUMENT ROOT/laravel/request.php like this:
public static function cli()
{
// This is a hack to make laravel work with fast-cgi
// Added by David - 03/27/13
if(!array_key_exists('argv', $_SERVER)) return false;
return defined('STDIN') || (substr(PHP_SAPI, 0, 3) == 'cgi' && getenv('TERM'));
}
Checking if the $_SERVER super global has the 'argv' key before returning false permits cli to continue to function while using php-cgi.
Inspired by your answer, this worked for me:
public static function cli()
{
if(array_key_exists('HTTP_HOST', $_SERVER)) return false;
return defined('STDIN') || (substr(PHP_SAPI, 0, 3) == 'cgi' && getenv('TERM'));
}