Laravel storage fake appears to be not working in github actions - github-actions

Locally everything works great:
Storage::fake('local');
$file = UploadedFile::fake()->image('watch.jpg');
$watchData = [
'model' => 'beatae unde adipisci',
'size' => '50',
'number' => 'm98300',
'metal' => 'deserunt',
'rrp' => '92840',
'status' => 'discontinued',
'brand_id' => '2',
'new_image' => $file,
];
$response = $this->post('/watch', $watchData);
Storage::disk('local')->assertExists('mg/jc-int/watch-images/1.jpg');
When I try to run this same test as part of my deployment workflow in GitHub Actions:
1) Tests\Feature\WatchImagesTest::test_a_watch_image_can_be_created
Unable to find a file or directory at path [mg/jc-int/watch-images/1.jpg].
Failed asserting that false is true.
I've tried a few things but I think this is more that I'm not understand how either Storage::fake() works or how GitHub actions handles filepaths?

Found the issue.
In my controller that handles the image upload, I'm grabbing a folder from my config:
$folder = config('site.DO_SUBFOLDER');
This value is taken from my .env and wasn't being included in the deployment pipeline.

Related

LogicException: You must define a binary prior to conversion

snappy.php get this code
'pdf' => [
'enabled' => true,
'binary' => env('"C:\Program Files\wkhtmltox\bin\wkhtmltopdf-amd64.exe"'),
'timeout' => false,
'options' => [],
'env' => [],
],
and when i try this code for test html to pdf in web.php
Route::get('/', function () {
$snappy = App::make('snappy.pdf');
$snappy->generateFromHtml('<h1>hello</h1>','exemple.pdf');
return view('welcome');
});
The problem is the executable path.
If Snappy don't find the executable, he get this message.
Please mark the file as executable (chmod +x on linux)
You can see this documentation
The problem is your binary path, if you are using Windows you must use the path like this:
'binary' => '"C:\Program Files\wkhtmltox\bin\wkhtmltopdf-amd64.exe"'
And make sure the path to the .exe is correct.

Logstash - How to trigger Celery tasks through RabbitMQ

Can someone explain to me how I can trigger Celery tasks through Logstash?
Is it possible?
If I try to do that in PHP through the 'php-amqplib' library it works fine: (without using Logstash)
$connection = new AMQPStreamConnection(
'rabbitmq.local',
5672,
'guest',
'guest'
);
$channel = $connection->channel();
$channel->queue_declare(
'celery',
false,
true,
false,
false
);
$taskId = rand(1000, 10000);
$props = array(
'content_type' => 'application/json',
'content_encoding' => 'utf-8',
);
$body = array(
'task' => 'process_next_task',
'lang' => 'py',
'args' => array('ktest' => 'vtest'),
'kwargs' => array('ktest' => 'vtest'),
'origin' => '#'.'mytest',
'id' => $taskId,
);
$msg = new AMQPMessage(json_encode($body), $props);
$channel->basic_publish($msg, 'celery', 'celery');
According to the Celery docs:
http://docs.celeryproject.org/en/latest/internals/protocol.html
I'm trying to send the request in the json format, this is my Logstash filter:
ruby
{
remove_field => ['headers', '#timestamp', '#version', 'host', 'type']
code => "
event.set('properties',
{
:content_type => 'application/json',
:content_encoding => 'utf-8'
})
"
}
And Celery answer is:
[2017-05-05 14:35:09,090: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!
{content_type:None content_encoding:None delivery_info:{'exchange': 'celery', 'routing_key': 'celery', 'redelivered': False, 'consumer_tag': 'None4', 'delivery_tag': 66} headers={}}
Basically, Celery is not able to decode my message format or better... I'm not able to set the request in the JSON format :)
It's driving me crazy, thank you in advance for any clues :)
Forgot it, this is my output plugin in Logstash
rabbitmq
{
key => "celery"
exchange => "celery"
exchange_type => "direct"
user => "${RABBITMQ_USER}"
password => "${RABBITMQ_PASSWORD}"
host => "${RABBITMQ_HOST}"
port => "${RABBITMQ_PORT}"
durable => true
persistent => true
codec => json
}
From the information provided in this question, you can't.
When you're playing with the event in the ruby filter, you're actually playing with what will be put in the body of the message, while you'd like to set the rabbitmq headers and properties of your message.
Till that functionality has been tackled, I do not think you'll be able to achieve it unless of course you implement it yourself. After all, the plugin is available on github.
As Olivier said, right now is not possible but I've created a pull request to the official project.
https://github.com/logstash-plugins/logstash-output-rabbitmq/pull/59
If you are looking for a working version take a look to my clone:
https://github.com/useless-stuff/logstash-output-rabbitmq
You should be seriously scared about that code :)
I'm completely far away to be a Ruby developer
But it works :)

Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281

I have used kartik pdf extension to print my report in pdf format.Things are going well in my local computer but when i put my codes in server error appears like this:
Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281
In server i have uploaded yii2-mpdf folder inside kartik-v folder and also mpdf folder.
My code of controller for pdf print:
use kartik\mpdf\Pdf;
public function actionPearlFinancialReport()
{
$pdf = new Pdf([
//'mode' => Pdf::MODE_CORE,
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('_financial_report', ['model' => $model,'parameter'=>$parameter]),
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline'=> '.kv-heading-1{font-size:15px;text-align:center;}',
'options' => ['title' => 'Pearl Financial Report'],
'methods' => [
'SetHeader'=>['Pearl Financial Report'],
'SetFooter'=>['{PAGENO}'],
]
]);
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
}
What to do?
Try this
'cssFile' => '#vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
Try to register this extension with composer:
For example my work directory is c:\xampp\htdocs\my-project
In a command prompt -> cd c:\xampp\htdocs\my-project
And register with this command:
C:\xampp\htdocs\my-project>php c:\xampp\htdocs\composer.phar require kartik-v/yii2-mpdf "dev-master"
I always register kartik's extensions with this metod, I hope want to be useful for you too.

yii2 stripe include error (class not found)

Yii2 Framework.
Installed Stripe (https://github.com/stripe/stripe-php) by composer:
composer require stripe/stripe-php
And inserted to the view:
\Stripe\Stripe::setApiKey('sk_test_...');
$myCard = array(
'number' => '4242424242424242',
'exp_month' => 8,
'exp_year' => 2018
);
$charge = \Stripe\Charge::create(array(
'card' => $myCard,
'amount' => 2000,
'currency' => 'usd'
));
echo $charge;
And now framework can't find Class:
Error
Class 'Stripe\Stripe' not found
What should I do next?
Did you correctly include Composer's autoload file?
You should have a require statement similar to this near the beginning of your code:
require_once('vendor/autoload.php');
cf. Stripe's PHP library's README file and Composer's documentation.

How to set logFile path dynamically for different modules in yii

I want to set different logpath for each module so that all errors, warnings, should be categorize with module name as parent folder.
i.e
runtime/logs/module_name/errors.log
runtime/logs/module_name/warnings.log
runtime/logs/module_name/info.log.
currently log component is configured in config/main.php
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['info'],
'categories' => ['common\modules\*'],
'logFile' => '#runtime/logs/common.modules.info.log',
],
],
]
I want to dynamically assign logFile path value in above application configuration file, so that if any error, warning, info is called in any module it will automatically pick that module name and logs the information.
You can add log target dynamically from controller or module init.
$target = new FileTarget();
$target->logFile = \Yii::getAlias('#runtime') . '/custom.log'
$target->categories = ['log-category']
\Yii::$app->getLog()->targets = [$target];
But I think will be better create new FileTarget class and moved static settings like categories into it.