Category : phpunit

I was trying to learn PHPUnit on laravel and I got a little problem. I managed to make a test for data input and data validation but for updating the data somehow it didn’t work. This is my update function in controller public function update(PostRequest $request, PostModel $post) { $update = $request->all(); $update[‘category_id’] = $request->category; ..

Read more

Symfony 5.1.8 phpunit 7.5.20 php 7.4.12 When I run the tests without specifying a file, phpUnit can’t find any file. Folder Structure tests ├── bootstrap.php ├── TestTools │   └── MockService │   └── Helper.php └── UnitTests ├── WorkingExample2Tests.php └── WorkingExampleTests.php phpunit_phpstorm.xml <?xml version="1.0" encoding="UTF-8"?> <!– https://phpunit.readthedocs.io/en/latest/configuration.html –> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="./tests/bootstrap.php" > <php> <ini ..

Read more

I have the following class: <?php namespace Kata; class Template { public function calculateAdd(float $first, float $second): float { return ($first + $second); } } And I want to use PHPUnit to test all the possible scenarios, among them I want to test if the argument passed is invalid. public function invalidSums(): void { $this->assertEquals(‘InvalidArgumentException’,(new ..

Read more

I’m testing a API, in the setup i make a factory to create and save a user, after i request with curl. after that a clear the user in tearDown like the example below: private User user; /** * @before */ public function setup() { //open connection here $this->user = UserFactory::makeUser(); $this->user->save(); $this->sendRequestToLoginWihtThatUser($this->user); } //execute ..

Read more

I am developing a system using Laravel 7.28.4 In the system I have created a SMSService to be able to send SMS message, below is the SMSService code https://codeshare.io/aYjDRM below is the code which the unit test read for the testing of $response = $this->post(route(‘api.booking.update’, $booking->id), $data); https://codeshare.io/aVLAeR during running unit test i am using ..

Read more

Currently i want to create unit test to cover some function in my developed feature, but i a have problem when facing this kind of function, when the purpose of function is to retrieve result from database. public function saveMessage($request) { $validation = $this->validate($request); if($validation[‘status’]) { $input = $validation[‘detail’]; $data = [ ‘id’ => $input[‘id’], ..

Read more

How can I assert this: $this->assertEquals(‘incoming’, $payload[‘routerAction’]); Skipping the pipelines. I’m using phpleague/pipeline Code: class IncomingPipeline { public function __invoke(array $payload) { $router = $payload[‘router’]; $payload[‘routerAction’] = ‘incoming’; return (new Pipeline()) ->pipe(new DispatchIncomingEventStage()) ->pipe(BaseRouter::route($router)) ->process($payload); } } I basically want to skip the Pipeline OR set andReturn($payload) on them. Sourc..

Read more