I'm an absolute newbie to Unit Testing, but I feel the need to learn something about it while I'm making my switch to CakePHP 3.
Following the manual, I've installed phpunit through composer (the same as I did for the whole cake package), created an empty test database and given config/app.php the right informations on how to connect.
Through the bake plugin I've baked some tests (I've got 19 tests now). Each one of them is (correctly) marked as incomplete.
Now, I'm trying to write a test for one of my controller's index function, this is what I've done:
public function testIndex()
{
$this->Session([
'Auth' => [
'User' => [
'id' => 1,
'email' => 'test#test.com',
'level' => 'adm',
]
]
]);
$this->get('/invoices');
$this->assertResponseOk();
}
The problem is that it just doesn't work, and I don't know what is throwing that 500 error...
Status code is not between 200 and 204
Failed asserting that 500 is equal to 204 or is less than 204.
What am I doing wrong?
Related
I'm getting this error "Use of undefined constant SIGKILL - assumed 'SIGKILL'" from my AJAX request, that starts this artisan command ->
Artisan::call('queue:work', [
'connection' => 'database',
'--memory' => '700',
'--tries' => '1',
'--timeout' => '35000',
'--queue' => 'updates'
]);
I'm using Laravel 5.7 as framework for application.
Jobs are managed from database, configuration ->
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 18000,
],
Problem appeared recently.. That is weird, because troubles wasn't here before and all this "system" worked just fine. Now worker get some jobs done just fine, but then it drops to error, and writes to table "failed_jobs" in DB this ->
ErrorException: PDOStatement::execute(): MySQL server has gone away in /srv/migration-xxxxxx-xxxx-xxxxxx/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
As DB I'm using Microsoft Azure MySQL DB. Microsoft specialist after consultation find nothing .. server is working correctly. Queries are just fine, not that big to fail.
Please help, don't know what to do, or what is wrong...
hi i am save image in frontend and that show in frontend true and i test with many way to view that in backend but don't work.
please help me
my controller in backend
Yii::$app->params['uploadPath'] = Yii::getAlias('#frontend') .'/web/uploads/';
$path = Yii::$app->params['uploadPath'] . $model->image_web_filename;
$image->saveAs($path);
url my backend and frontend is seperate
backend:yii.com/:81
frontend:yii.com
i test these soloution but didn't work true:
https://stackoverflow.com/questions/23155428/how-to-get-root-directory-in-yii2
i inset two alias in aliases file in backend\config:
Yii::setAlias('#frontend', 'http://frontend.sample.dev');
Yii::setAlias('#backend', 'http://backend.sample.dev');
and use that in backend/web/index.php
require(__DIR__ . '/../config/aliases.php');
but i get this error:
An Error occurred while handling another error:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in
/var/www/blog/vendor/yiisoft/yii2/base/Module.php:532
Stack trace:
#0 /var/www/blog/vendor/yiisoft/yii2/web/ErrorHandler.php(95):
yii\base\Module->runAction('site/error')
#1 /var/www/blog/vendor/yiisoft/yii2/base/ErrorHandler.php(111):
yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#2 [internal function]: yii\base\ErrorHandler-
>handleException(Object(yii\web\NotFoundHttpException))
#3 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "post/index".' in
/var/www/blog/vendor/yiisoft/yii2/base/Module.php:532
Stack trace:
#0 /var/www/blog/vendor/yiisoft/yii2/web/Application.php(102):
yii\base\Module->runAction('post/index', Array)
#1 /var/www/blog/vendor/yiisoft/yii2/base/Application.php(380):
yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /var/www/blog/backend/web/index.php(18): yii\base\Application->run()
#3 {main}
Next exception 'yii\web\NotFoundHttpException' with message 'Page not
found.' in /var/www/blog/vendor/yiisoft/yii2/web/Application.php:114
Stack trace:
#0 /var/www/blog/vendor/yiisoft/yii2/base/Application.php(380):
yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /var/www/blog/backend/web/index.php(18): yii\base\Application->run()
#2 {main}
i'm pretty late to the party
but i got a few bones to pick with this solution provided.. so here it goes:
you mention you have different front and back configurations
so you are serving different folders for yii.com/:80 and yii.com/:81 respectively /frontend/web and /backend/web.
keeping this in mind,
no amount of aliases can make content of one of them available to the other.
the yii-advanced-app has #frontend and #backend aliases defined in common/config/bootstrap
Yii::setAlias('#common', dirname(__DIR__));
Yii::setAlias('#frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('#backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('#console', dirname(dirname(__DIR__)) . '/console');
DO NOT CHANGE THESE unless you know very well what you're doing.
Yii is using these aliases to autoload classes defined under these namespaces common, frontend, backend and console. this exact thing is causing the ridiculous chain of "errors occurring while handling other errors"
more details on Yii autloading documentaion
you can simply share content of these folders by creating a symlink from frontend/web/uploads to backend/web/uploads.
your webserver config (or .htaccess) will require the +FollowSymLinks option
Yii can manage this if you add a few lines to the environments/index.php file
'Development' => [
// .. other options
'setWritable' => [
// .. leave the default stuff there
'frontend/web/uploads',
],
'createSymlink' => [
// link => real folder
'backend/web/uploads' => 'frontend/web/uploads',
]
],
'Production' => [
// ..
'setWritable' => [
// ..
'frontend/web/uploads',
],
'createSymlink' => [
// link => real folder
'backend/web/uploads' => 'frontend/web/uploads',
]
],
and then run the init command again, just like in the installation guide (you do have to option to not overwrite local config files)
if you are running under windows, this might now ask you for elevated privileges
php init
or if you chose to make the symlinks manually you can try this quick guide
you can try this solution :
Yii::setAlias('#frontend', 'http://frontend.sample.dev');
Yii::setAlias('#backend', 'http://backend.sample.dev');
and if you upload files in backend set the src parameter of image to
Yii::getAlias('#backend/path/to/your/image/file');
and if you save your files in frontend replace #backend with #frontend
create this function in components folder
namespace common\components;
use Yii;
class Helper extends \yii\web\Request {
public static function getFrontendUrl($path) {
$frontUrl = str_replace('/adminpanel', '', $path);
return $frontUrl;
}
}
and use in backend :
$path \common\components\Helper::getFrontendUrl(Yii::$app->request->baseUrl).$img;
notic: in frontend You do not need
I created a basic laravel passport authentication and created callback and redirect to authorize user below is my code
Route::get('/redirect', function () {
$query = http_build_query([
'client_id' => 4,
'redirect_uri' => 'http://localhost:8000/callback',
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://localhost:8000/oauth/authorize?'.$query);
});
Route::get('/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('http://localhost:8000/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 4,
'client_secret' => 'MUqUFrtAx3ix84zFTxwqQXA5PQDY7SWwVFW9tCNX',
'redirect_uri' => 'http://localhost:8000/callback',
'code' => $request->code,
],
]);
return json_decode((string) $response->getBody(), true);
});
I followed the steps provided on https://laravel.com/docs/5.4/passport but when i click on authorize button the page keeps loading without any response and i have to restart artisan serve. What could be the possible issue?
The issue is when using php artisan serve, it uses a PHP server which is single-threaded.
The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked.
You can do this solution:
When making calls to itself the thread blocked waiting for its own reply. The solution is to either seperate the providing application and consuming application into their own instance or to run it on a multi-threaded webserver such as Apache or nginx.
Or if you are looking for a quick fix to test your updates - you can get this done by opening up two command prompts. The first would be running php artisan serve (locally my default port is 8000 and you would be running your site on http://localhost:8000). The second would run php artisan serve --port 8001.
Then you would update your post request to:
$response = $http->post('http://localhost:8001/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 4,
'client_secret' => 'MUqUFrtAx3ix84zFTxwqQXA5PQDY7SWwVFW9tCNX',
'redirect_uri' => 'http://localhost:8000/callback',
'code' => $request->code,
],
]);
This should help during your testing until you are able to everything on server or a local virtual host.
In your /redirect route you are providing same localhost:8000 . change your redirect_uri and same mistake in callback route .
Change Your
'redirect_uri' => 'http://localhost:8000/callback',
To
'redirect_uri' => 'http://localhost:8001/callback',
Note: Im running other project on port 8001 .you can change it with yours :)
try to use XAMPP or another web server instead of just php artisan serve
I am currently trying to setup some data collections for our app using the full elk stack (Beats - Logstash - ElasticSearch-Kibana). So far everything is working as it should but I have a requirement to capture statistics on the exceptions thrown by the applications (e.g. java.lang.IllegalArgumentException)
I am not really interested in the stack trace itself so I went ahead and added a separate grok filter just for the exception.
Example of Message:
2016-11-15 05:19:28,801 ERROR [App-Initialisation-Thread] appengine.java:520 Failed to initialize external authenticator myapp Support Access || appuser#vm23-13:/mnt/data/install/assembly app-1.4.12#cad85b224cce11eb5defa126030f21fa867b0dad
java.lang.IllegalArgumentException: Could not check if provided root is a directory
at com.myapp.io.AbstractRootPrefixedFileSystem.checkAndGetRoot(AbstractRootPrefixedFileSystem.java:67)
at com.myapp.io.AbstractRootPrefixedFileSystem.<init>(AbstractRootPrefixedFileSystem.java:30)
at com.myapp.io.s3.S3FileSystem.<init>(S3FileSystem.java:32)
at com.myapp.io.s3.S3FileSystemDriver.loadFileSystem(S3FileSystemDriver.java:60)
at com.myapp.io.FileSystems.getFileSystem(FileSystems.java:55)
at com.myapp.authentication.ldap.S3LdapConfigProvider.initializeCloudFS(S3LdapConfigProvider.java:77)
at com.myapp.authentication.ldap.S3LdapConfigProvider.loadS3Config(S3LdapConfigProvider.java:51)
at com.myapp.authentication.ldap.S3LdapConfigProvider.getLdapConfig(S3LdapConfigProvider.java:42)
at com.myapp.authentication.ldap.DelegatingLdapConfigProvider.getLdapConfig(DelegatingLdapConfigProvider.java:45)
at com.myapp.authentication.ldap.LdapExternalAuthenticatorFactory.create(LdapExternalAuthenticatorFactory.java:28)
at com.myapp.authentication.ldap.LdapExternalAuthenticatorFactory.create(LdapExternalAuthenticatorFactory.java:10)
at com.myapp.frob.appengine.getExternalAuthenticators(appengine.java:516)
at com.myapp.frob.appengine.startUp(appengine.java:871)
at com.myapp.frob.appengine.startUp(appengine.java:754)
at com.myapp.jsp.KewServeInitContextListener$1.run(QServerInitContextListener.java:104)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.file.NoSuchFileException: fh-ldap-config/
at com.upplication.s3fs.util.S3Utils.getS3ObjectSummary(S3Utils.java:55)
at com.upplication.s3fs.util.S3Utils.getS3FileAttributes(S3Utils.java:64)
at com.upplication.s3fs.S3FileSystemProvider.readAttributes(S3FileSystemProvider.java:463)
at com.myapp.io.AbstractRootPrefixedFileSystem.checkAndGetRoot(AbstractRootPrefixedFileSystem.java:61)
Example of grok statement:
grok {
patterns_dir => ["./patterns"]
match => ["message", "%{GREEDYDATA}\n%{JAVAFILE:exception}"]
}
Testing on the grok debugger shows correct results:
{
"GREEDYDATA": [
[
"2016-11-15 05:19:28,801 ERROR [App-Initialisation-Thread] appengine.java:520 Failed to initialize external authenticator myapp Support Access || appuser#vm23-13:/mnt/data/install/assembly app-1.4.12#cad85b224cce11eb5defa126030f21fa867b0dad"
]
],
"exception": [
[
"java.lang.IllegalArgumentException"
]
]
}
Problem
When I add the configuration to logstash it captures the Caused string instead of the exception name, even though the "Caused" string is after another new line character. However it works perfectly for other exception messages such as :
016-11-15 06:17:49,691 WARN [SCReplicationWorkerThread-2] ClientJob.java:207 50345 Error communicating to server `199.181.131.249':`80'. Waiting `10' seconds before retrying... If you see this message rarely, the sc will have recovered gracefully. || appuser#vm55-12:/mnt/deployment/install/app app-3.1.23#cad85b224cce11eb5defa126030f21fa867b0dad
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:223)
at java.io.DataInputStream.readBoolean(DataInputStream.java:242)
at com.myapp.replication.client.ClientJob.passCheckRevision(ClientJob.java:279)
at com.myapp.replication.client.ClientJob.execute(ClientJob.java:167)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)
Any advice would be appreciated.
Thanks
Did you setting the mutiline in the input or filebeat input ,
like this to show the pattern start with ISO8601
I think maybe you mutiline not fetch the whole line
input {
beats {
port => 5044
codec => multiline {
pattern => "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[\.,][0-9]{3,7} "
negate => true
what => "previous"
}
}
}
I'm using Kohana framework v3.3.1. Here's the default route in my bootstrap.php,
Route::set('default', '(<controller>(/<action>(/<id>)))')
->filter(
function(\Route $route, $params, \Request $request) {
$params['action'] = str_replace('-', '_', $params['action']);
return $params;
}
)
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
Whenever I add "filter" to the route, I get the following error,
Fatal error: Uncaught Kohana_Exception [ 0 ]: Invalid Route::callback specified ~ SYSPATH/classes/Kohana/Route.php [ 391 ] thrown in /system/classes/Kohana/Route.php on line 391
The same code works fine in my localhost (ubuntu 14.04) but doesn't work in Bluehost. Any help would be greatly appreciated.
Figured it out. Though bluehost implements PHP v5.4, code corresponding to v5.2 only works.
Route::set('testing', 'foo')
->filter(array('Class', 'method_to_process_my_uri'));
Reference: Kohana v3.3 User Guide