I am getting this error in my log file when I run codeception test case. How to fix this?
Code:
public function testUpdatePhone(FunctionalTester $I)
{
$I->wantTo('Test update phone');
$I->sendPUT('/admin/phone/100', [
'label' => 'My new label'
]);
$I->see('Phone Number updated successfully.');
}
Command:
./vendor/bin/codecept run
tests/functional/AdminPhoneTestCest.php:testUpdatePhone
Error in Log file:
[2015-06-06 05:34:02] local.ERROR: exception
'Illuminate\Session\TokenMismatchException' in
/var/www/xxxx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:46
Thanks in advance :)
This issue has been fixed by adding middleware method as follows
public function handle($request, Closure $next)
{
if ($request->header('user-agent') == 'Symfony2 BrowserKit') {
return $next($request);
}
throw new TokenMismatchException;
}
Reference: https://laracasts.com/discuss/channels/general-discussion/latest-v5-laravelframework-csrfmiddleware-changes-broke-codeception-functional-tests
If you're using phantomjs, you will need to ensure you have clear_cookies: true in your settings as the normal restart: true doesn't seem to be supported for phantomjs, so it uses the same token which is invalid in subsequent tests.
Related
when i try to run serve in laravel i got this error
Symfony\Component\Process\Exception\RuntimeException
The provided cwd "C:\laravel projects\eccomer/../public_html" does
not exist.
at C:\laravel
projects\eccomer\vendor\symfony\process\Process.php:344
340▕ }
341▕ }
342▕
343▕ if (!is_dir($this->cwd)) { ➜ 344▕ throw new RuntimeException(sprintf('The provided cwd "%s" does not exist.',
$this->cwd));
345▕ }
346▕
347▕ $this->process = #proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs,
$this->options);
348▕
1 C:\laravel
projects\eccomer\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:128
Symfony\Component\Process\Process::start(Object(Closure))
2 C:\laravel
projects\eccomer\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:68
Illuminate\Foundation\Console\ServeCommand::startProcess()
i try anything but does not work
i fixed error like this :
in app/Providers/AppServiceProvider.php file in boot funcation i copy this code:
public function boot()
{
Paginator::useBootstrap();
}
and my problem fixed
I'm having problems with validator on Route.resource(). The validator is not been applied and when I run the command "adonis route:list" the av:TrainingPlan and Workout validators are not being listed. You can see that my other validators are working on single endpoint verb like "Route.post" on /users, /sessions/ and /passwords. On app.js under start folder I checked that the register was made too and all validator was generated by adonis cli.
My routes file was made based on documentation:
Route.group(() => {
Route.post('files', 'FileController.store')
Route
.resource('/training-plans', 'TrainingPlanController')
.apiOnly()
.validator(new Map([
[['training-plans.store'], ['TrainingPlan']]
]))
Route
.resource('/workouts', 'WorkoutController')
.apiOnly()
.validator(new Map([
[['workouts.store'], ['Workout']]
]))
}).middleware(['auth'])
TrainingPlan Validator:
'use strict'
class TrainingPlan {
get validateAll () {
return true
}
get rules () {
return {
title: 'required',
description: 'required',
start_date: `date|before:${new Date()}`,
end_date: `date|before:${new Date()}`
}
}
}
module.exports = TrainingPlan
What I'm missing out?
adonis route:list command result
The problem was resolved removing / before /workouts and /training-plans route.
I did not tested putting / before workouts.store and training-plans.store inside Map validator.
I created a webhook to get informations about checkout sessions :
public function stripeWebhookCheckout(Request $request)
{
\Stripe\Stripe::setApiKey(env("STRIPE_SECRET"));
// You can find your endpoint's secret in your webhook settings
$endpoint_secret = 'whsec_fVBkAmCztUTacQKZiyjmcq6QQrl8lKL1';
$payload = #file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload,
$sig_header,
$endpoint_secret
);
} catch (\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
// Handle the checkout.session.completed event
if ($event->type == 'checkout.session.completed') {
$session = $event->data->object;
// Fulfill the purchase...
handle_checkout_session($session);
$stripeSessionId = $session['id'];
if (isset($stripeSessionId)) {
$payment = Payment::where('stripe_sessioncheckout_id', '=', $stripeSessionId)->first();
$payment->status = "success";
$payment->data = $session;
$payment->save();
}
}
http_response_code(200);
}
I use stripe-cli to test my webhook in local. And i have this kind of result
$ stripe listen --forward-to jvlb.test/api/stripe/webhook/checkout
> Ready! Your webhook signing secret is whsec_sc9Gh9A6zx3IOfBpH62F9DdPYIhSUYtw (^C to quit)
2019-11-28 16:19:06 --> charge.succeeded [evt_1FjsW5FIYszmshR0eGSB9GDo]
2019-11-28 16:19:06 <-- [400] GET https://jvlb.test/api/stripe/webhook/checkout [evt_1FjsW5FIYszmshR0eGSB9GDo]
To debug it i changes the http_response_code(400) and I realised it generate a SignatureVerificationException.
My question is, how can i debug this ? Is it the $_SERVER['HTTP_STRIPE_SIGNATURE'] who is wrong ?
Thanks
i found a solution, if it can help people in the future :
I made a mistake in the way i use stripe-cli, i forgot "https://".
The good way is :
stripe listen --forward-to https://jvlb.test/api/stripe/webhook/checkout
And then i had few error of code to manage. I just used the tail command on my log file
tail -f storage/logs/laravel-2019-11-29.log
I just use doc example,but get the error
exception 'Predis\ClientException' with message 'Command 'THROTTLE' is not a registered Redis command.
I havce search a lot about redis command,but nothing about throttle.
public function handle()
{
// Allow only 2 emails every 1 second
Redis::throttle('my-mailtrap')->allow(2)->every(1)->then(function () {
$recipient = 'steven#example.com';
Mail::to($recipient)->send(new OrderShipped($this->order));
Log::info('Emailed order ' . $this->order->id);
}, function () {
// Could not obtain lock; this job will be re-queued
return $this->release(2);
});
}
What should I do?Any help,Thanks!
throttle method is defined in Illuminate/Redis/Connections/PredisConnection.
The Redis facade allows for you to get the connection using
Redis::connection()
->throttle('my-mailtrap')
//...
http://laravel.com/docs/5.8/redis
I'm trying to test all the routes on my api but only the first request gets 200, all the other following requests get 404. But if I run any test individually using (phpunit --filter test_something) it works.
<?php
class ProgramTest extends TestCase {
/** #test */
public function it_returns_index() {
$this->get('api/v1/test')
->assertReturnOk(['limit' => 10]);
}
/** #test */
public function it_returns_show() {
$this->get('api/v1/test/12')
->seeJson(['id' => 12]);
}
}
getting error as
PHPUnit 4.8.23 by Sebastian Bergmann and contributors.
.F
Time: 2.33 seconds, Memory: 20.25Mb
There was 1 failure:
1) ProgramTest::it_returns_show
Invalid JSON was returned from the route. Perhaps an exception was thrown?
You need to fix the problem in Routes.php I think. I have seen a similar question that has been answered in the below link. Hope this would solve you. The Route modification that was done is as per the below link
$phpunit = simplexml_load_file('phpunit.xml');
foreach (File::allFiles(__DIR__ . '/Routes') as $partial) {
if ($phpunit->php->xpath('env[#name="APP_ENV"]')[0]['value'] == 'testing') {
require $partial->getPathname();
} else {
require_once $partial->getPathname();
}
}
https://laracasts.com/discuss/channels/testing/test-api-404-on-multiple-requests