Test Driven Laravel - e01 - Introduction, PHPUnit Setup & Books Test Part 1
HTML-код
- Опубликовано: 15 ноя 2024
- In this lesson, we are starting a project from scratch including setting up sqlite for testing, initializing Git and writing our first tests to add Books into our library.
For the best experience, follow along in our interactive school at www.coderstape...
DigitalOcean Referral
m.do.co/c/7dce...
Resources
Course Source Code
github.com/cod...
Hit us up on Twitter with any questions or comments @codertape ( / coderstape )
About This Course
We are tackling a brand new series to showcase a real-world workflow that you may adapt to your liking. We will be building a library management software for our local library that will include the ability to checkout books, reserve books and much more. We will be doing this through the TDD methodology, come along as we dissect Test Driven Laravel Development.
I hope you are alright and doing great. I don't know why you stopped posting new videos. You are an amazing teacher and I think your channel was about to become a huge one.
He's really a good teacher. Do you have any news about him?
I totally agree! This the best Laravel teacher on the internet.. i learned a lot from him. I hope he's coming back for some new fresh Laravel 9 tutorials 😇
There is no one on RUclips that goes as deep into a piece of software as you do.
Holy moly you're on a roll.
agree
I agree. It is tough to get a decent TDD Tutorial. Thanks. Yours was informative and easy to follow.
@Ricky Kian I watch them on my own platform called NoMercy TV 😉 it's still a wip tho.
یکی از بهترین مدرسان کدنویسی شما هستید....
یه نکاتی گفتید که اصن من ندیده بودم....
رایگان این همه نکته ی طلایی رو ارائه دادید....
بی نهایت تشکر بخاطر این دوره و چند دوره ی api که اونم فوق العاده کاربردی بود.
1 word. PERFECTION. Thanks a lot victor
I never think that someday i am going to learn phpunit because this is such an advance part in php, but now I'm here learning this! Thank you Sir Victor for your modern teaching style! It helps me so much in my path! It feels like I am a real programmer lol.
it just takes one day to decide to start testing your applications and then you'll never go back
@@CodersTape Yes Sir copy :)
your content is exactly equal as Laracasts videos that i have been watching since years
Seems to me this should be the first thing learnt by anyone approaching any form of development. Ta muchly!
Dude you are really doing amazing job indirectly you’re enhancing developers and the future of development! Thanks man!
Very few good people like you.
I know I am pretty off topic but do anybody know of a good place to watch newly released series online?
Thanks 🙏🙇🙏🙇🙏🙇🙏🙇 for starting this series
tank you Mr. Victor, you helped me a lot
First youtuber i trust, i wait, and like before watching. Keep tutor-coding, Victor. You,re great!
Thank you boss.
I'm expecting this series from you. As you explanation power is very strong.
You are very great man, really! your way to explain things, the code you write, simply amazing! Cheers from Italy.
Best series about TDD with Laravel, no doubt!!!
Thanks! Glad to help.
Awesome tutorial. The best one I've managed to find on RUclips. Cheers
the BEST as always!
I am following this course
i'm envious on how he is really efficient in using PHPstorm. with method extraction, inline, etc shortcuts.
This is call Test Driven Development!!
Amazing video.
I love your channel. You do not have as many followers as you deserve, but keep up the good work ... definitely better than many paid courses.
Greetings from Argentina
I was waiting for this series, thanks Man !!!
Very informative videos bro, I love how you explain the reason behind everything you do, and why it's not done differently, most tutorials are just 'do this.. do this.. do this' and they never tell why. This is a great series, I hope you continue this for a very long time.
We miss you, hope you will be back soon to us :)🙂
My solution for creation alias "pf" on Windows:
Create pf.bat in project directory with this code inside:
@echo off
cls
vendor\bin\phpunit --filter %1
Now you can run in cmd
pf a_book_can_be_added_to_the_library
And dont forget about /** @test */ before public function a_book_can_be_added_to_the_library()
phpstorm can do unit test comand instantly
Or just use a better console, like Cmder, Git Bash...
or just use jetbrains intergration of phpunit testing
You are amazing
How awesome is that!
Very helpful, please don't stop to share such stuff. Subscribed ;)
Great tutorial. Thank you.
Thank you so much Bro!. This was very informative and helpful.
Thanks man for your effort and time
Hey dude thanks a lot I learn lot of things in your videos.
Thanks so much for your videos, are great!
Hi, I have been going through a few episodes of your various series and i find the awesome !. I love the way you put across the various concepts. Way to go !!! Thank you.
І нарешті це несамовите відчуття радості, коли твій перший юніт тест пройшов!!!)))
Very inspiring, but for update i would suggest to use PUT and stick to modern development with RESTful requests :) Having said that you used PATCH later, that will work as you are partly updating.
Your tutorials are awesome but it would be really great if you could always show the keyboard shortcuts when you're using them (I realize that would affect only new videos but it's definitely something I'd like to see)
What about if I want to test an API resource? Which url's I've to use?
Great video.
Just wow man
How awesome is that!!!!!
Yup
Hi, I'm not sure if you read this, if I don't want the tables to be truncated, because I have a working app, how can I reset only the one table I have created now, and leave the rest as is? Also if I add tests later, when my table is in constant use, I need the same: the data that is in the table shouldn't be deleted. Thank you
Hi Victor, before I start the course, how do u set up the UI of item2 terminal?
thank you!
This is so awesome! Thank you
I've got a CSRF token mismatch error when I test the update method in postman, and every test I run creates a new table entry in my database table.
Great tutor!.
Hello,
Thanks for the test driven developpement tutoriel, l'd like to know why you don't use Form Requests to extract validation logic in another class? instead of to have a protected methode to validate data in a controller.
Great job
I like to save those extractions to when it’s absolutely necessary. It adds a lot of technical debt to an otherwise very simple protected method. I just don’t believe a 2 field form requires a class just for validation. I like the simplest route unless it’s absolutely necessary and then you’ll get the code smell and require a refactor.
can you do a video on how to setup phpstorm specifically for laravel (plugins, settings, or other hacks)
What are your suggestions for the newcomers?
This is a good video. I have one question though, even using TDD, would it be acceptable to create resource controllers so that the routes are already registered? Or, is it better to use the red, green, refactor system and work your way to developing said resource controller. As a shortcut, Artisan can make your model, migration, resource controller, seeders, and factories with one command. When it comes to TDD, especially within laravel, should these "shortcuts" be ignored and developed as you create tests?
no, u should follow best practice at all and what u said is the best solutions
I love it, thanks
Waiting Complete Online Laravel E commerce Development Series (Product - Category - Subcategory ), with all its packages
We might tackle that some day
@@CodersTape What you recommend from Open sources available?
I'm finishing a ecommerce with laravel, with products ratings and discounts..
Thank you so much!!!
Hi, Victor. Real thumbs up!! watched your Full Course and these TDD. Perfect. Thanks a lot!!
but i have 2 problem.
first $this->withoutExceptionHandling() give me undefind error
second how set up mysql for testing.
btw i'm on windows and laravel 6.*
Great Video. A quick question! Could we use Form Request for the validation instead of the protected method or are Form Requests a different concept?
In some point of this course, you'll explain or use Dusk?
Hi. Thank you for this great tutorial! I have an error, somebody can help me what is the solution? Method Illuminate\Http\Response::assertEquals does not exist. (Laravel 6.17, PHPUnit 8.5.2)
Man you've made an understandable video but I'm stuck Sir how do you use pf test-function-name
I'm stuck please help
My OS is windows 10
couldn't you do an env.testing?? sinf in phpunit.xml the app_env is testing?
How did you open phpstorm by just typing "phpstorm"? And is it possible on a windows machine? :)
press the windows key and type phpstorm
why do you write those test in Feature folder instead of Unit folder?
Hi thanks for the nice Tutorials,
but a POST should return a 201 status for creating a new dataset and the $this->assertDatabaseHas(..., [...]); method its a bit cleaner then check the count .
Hi, I am new to this testing thing, I followed all the steps properly but when testing show no tests executed. I run the command :- phpunit --filter a_book_can_be_added_to_library ?? Am I doing something wrong??
Before the public function a_book_can_be_added, you must have /** @test */
github.com/coderstape/library/blob/51acb0edb44f583771dbd9ea786cec2571c7ee6c/tests/Feature/BookManagementTest.php#L14
You need to run phpunit from vendor/bin/ directory and then pass in the method name
i.e.
./vendor/bin/phpunit --filter a_book_can_be_added
After searching for a while, I come to understanding that $this->withoutExceptionHandling() should not be used when we test the case which we want it to be "wrong" such as request validation, unauthentication, etc... else it will throw out exception and will not reach the assertion statement below...
What is your terminal, I like to install
I spent the whole video being like "jesus this sounds like a LOT of work for very little benefit, what's even the point of testing things before I write them"
Then at the 25 minute mark when he started refactoring the code knowing from the tests it wouldn't break anything, I suddenly went back to all the nightmarish times I had to look for what part of my refactoring broke something and everything clicked.
❤️❤️❤️❤️
what is laravel version that you used ?
great
I work with laravel 6. There is a problem because phpunit.xml data is not read. That is why my APP_ENV is local instead of testing. Any solution?
aww, that was just caching.. php artisan config:clear
any plans of Docker, kubernates with laravel?
Not at this time. But maybe in the future
Thank you for this great tutorial, for those who I have not followed your previous course it's probably worth covering OR those who are having issues:
First of all, if you get "No tests executed!", set your phpunit path accordingly. Try: ./vendor/bin/phpunit --filter
secondly, install SQLITE if not done previously, see: ruclips.net/video/wXEZZ2JT3-k/видео.html&vl=en
and finally, create database.sqlite in database folder or see stackoverflow.com/questions/31132270/set-sqlite-as-database-for-unit-testing-in-laravel-5-1 . this was quickly shown in the video but not explained.
Once again, thank you for making these tutorials.
Thanks
if any one face this problem Response status code [419] does not match expected 200 status code. just use this trait use WithoutMiddleware; in the test class
I can't find assertCount in Laravel documentation
That’s correct. assertCount is a phpunit method. You can check it out here
phpunit.readthedocs.io/en/7.4/assertions.html
Search for assertCount()
phpunit.readthedocs.io/en/8.1/assertions.html#assertcount
I met a problem $response->assertOk();
error show: BadMethodCallException: Method assertOk does not exist
help me!
Use ->assertStatus(200)
I like your terminal theme/colors. how can i do that?
check this out github.com/robbyrussell/oh-my-zsh/wiki/Themes
🤯🤯🤯🤯🤯🤯🤯
Where are you bro!!???
This is all and well until the client demands that you finish the entire application within 30mins. Hope you have a tutorial on how to ask the client for more time to perform TDD.
Nope but I am certainly interested if you find one! :)
@@CodersTape Sadly i haven't. Been searching for thousands of years that applies to all project and client types, but there's none. But all in all, very nice tutorials! Keep it up.
if a client wants a custom application in "30 mins" then I suggest you drop that client immediately :)
😭 I’ve met plenty of clients with bigger expectations than wallets
I get the following error when I use 'alias pf', alias : This command cannot find a matching alias because an alias
with the name 'pf' does not exist. whats the solution please help..
I got it..I didnt use vendor\bin\phpunit
1) Create pf.bat in project directory
2) writes the following contents in pf.bat
@echo off
cls
vendor\bin\phpunit\ --filter %1
3) Run this command in terminal
.\pf test-function-name ex:a_title_is_required
Don't forget to write /** @test */ before test name
How can we create an alias that you've shown in the video like "alias pf", can anyone guide me?
jonsuh.com/blog/bash-command-line-shortcuts/
Simple
alias pf='clear && phpunit --filter'
Now you can just type
pf a_book_can_be_added
and there you go...
How to perform this with MySQL?
I tried to use MySQL instead of SQLite but it always returns
No tests executed!
Configuration read from C:\xampp\htdocs\learningTDD\phpunit.xml
Make sure that you have the /** @test */ notation before every test.
@@CodersTape i m having this error, after running phpunit --filter ....
PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285PHPUnit 3.7.21 by Sebastian Bergmann.
Configuration read from C:\Users\dell\Desktop\Dashboard\phpunit.xml
@@overlordmarvel12
You need to run phpunit from vendor/bin/ directory and then pass in the method name
i.e.
./vendor/bin/phpunit --filter a_book_can_be_added
Sir, Please make a video of custom login using laravel.
And also make a video about laravel model relationship deeply.
Please please please please sir.
🙏🙏🙏🙏🙏🙏
Watch he's Instagram clone video he covered it there
Where have you gone. Did something happened to you?. You stopped posting all of a sudden. Not even a community note...
you leave RUclips?
This will not work with laravel 8 outdated.
It works for me on Laravel 8.