StudyStream+
Git Flow Part 1 - What is Git Flow
updated
👨💻 The final code can be found on GitHub:
Bubble Sort - github.com/study-stream-plus/bubble-sort
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - How Bubble Sort Algorithm works
01:59 - How to code a Bubble Sort Algorithm
#bubblesort #gcse #computerscience #pythonbeginners #algorithm
👨💻 The final code can be found on GitHub:
Linear Search - github.com/study-stream-plus/linear-search
Binary Search - github.com/study-stream-plus/binary-search
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Intro
00:11 - Linear Search Algorithm Explained
01:01 - How to code the Linear Search Algorithm
05:23 - Binary Search Algorithm Explained
07:07 - How to code the Binary Search Algorithm
#binarysearch #linearsearch #gcse #computerscience #pythonbeginners
New Commit Flow:
youtu.be/SjdzqjBVYfk
Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
👨💻 The final code can be found on GitHub:
Simple Factory - github.com/study-stream-plus/simple-factory
Factory Method Pattern - github.com/study-stream-plus/factory-method-pattern
🛠️ Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
🛠️ 2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
📚 Contents:
00:00 - Intro
00:27 - Simple Factory
08:13 - Factory Method Pattern
#php #computerscience #designpatterns
🐍 See the full free GSCE Computer Science Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Intro
00:47 - Set default state of program
01:46 - Presence check
03:08 - Length check
04:21 - Type check
06:39 - Range check
09:22 - Format check
10:51 - Verification
#gcse #computerscience #ocr #python #pythonbeginners #validation
#verification #studystream+
🐍 See the full free GSCE Computer Science Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Intro
01:00 - What is a Global Variable
02:00 - What is a Local Variable
#gcse #computerscience #ocr #python #pythonbeginners #globalvariables
#scope #studystream+
🐍 See the full free GSCE Computer Science Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - What is a Function
05:35 - Write is a Procedure
#gcse #computerscience #ocr #python #pythonbeginners #pythonfunction #procedures #studystream+
🐍 See the full free GSCE Computer Science Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Create a file
01:03 - Write to a file
02:20 - Append to a file
03:39 - Read from a file
#gcse #computerscience #ocr #python #pythonbeginners #pythonfile #studystream+
🐍 See the full free GSCE Computer Science Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Casting
03:48 - String concatenation
06:45 - How Python sees a string
08:33 - Searching a string
11:15 - String functions
#gcse #computerscience #ocr #python #pythonbeginners #pythonstrings #studystream+
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - `for` loop basic example
02:30 - `for` loop List example
04:03 - `for` loop Dictionary example
06:06 - `while` loop
#gcse #computerscience #ocr #python #pythonbeginners #pythonloops #studystream
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
🔗 Links
1. Python docs Lists - docs.python.org/3/tutorial/datastructures.html#data-structures
2. Python docs Dictionaries -docs.python.org/3/tutorial/datastructures.html#dictionaries
📚 Contents:
00:00 - What is a List
04:46 - What is a Dictionary
#gcse #computerscience #ocr #python #pythonbeginners #pythonlists #pythondictionary
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - What is Sequence
00:31 - How to write an `If` statement
#gcse #computerscience #ocr #python #pythonbeginners #ifstatement
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Intro
00:31 - Calculate area with user input
04:11 - Mathematical operators
06:08 - Comparison operators
09:00 - Logical operators
#gcse #computerscience #ocr #python #pythonbeginners #pythonoperators
🐍 See the full free GSCE Python course here:
youtube.com/watch?v=lv8Tl5lBJC0&list=PLrIm-p2rpV0Hczso9dnu_sAJucaaAD_Hc
📖 GSCE Computer Science Paper 2022 Walkthrough (OCR J277/02)
youtube.com/watch?v=bmrVVtvtZGY
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚 Contents:
00:00 - Intro
00:09 - What is a variable
00:25 - Assigning a String to a variable
02:05 - Assigning an Integer to a variable
03:25 - Assigning a Float to a variable
04:00 - Assigning a Boolean to a variable
06:30 - Naming variables (Camel case and Snake Case)
11:02 - What is a constant
#gcse #computerscience #ocr #variablesinpython #python #pythonbeginners
Link to BBC data types table: bbc.co.uk/bitesize/guides/zb3yb82/revision/2
00:15 - Question 5 - a - i
00:32 - Question 5 - a - ii
02:07 - Question 5 - a - iii
05:29 - Question 5 - b - i
14:24 - Question 5 - b - ii
16:09 - Question 5 - c - i
17:56 - Question 5 - c - ii
20:27 - Question 5 - d
24:09 - Question 5 - e
👨💻 The final code can be found on GitHub:
github.com/study-stream-plus/rock-paper-scissors
🐍 More Python tutorials from us:
youtube.com/watch?v=OqAVcsLcob8&list=PLrIm-p2rpV0HTT5PWA8O2djcNN5ONx-df
🛠️ Tools:
1. PyCharm Community Edition - Free Official Download jetbrains.com/pycharm/download/#section=windows
📚Contents:
00:00 - Intro
00:29 - Determine user and computer weapon choices
02:26 - Determine winner of the game
05:30 - Play again functionality
07:15 - Refactor to functions
10:34 - Breaking down the problem
#python #pythonprojects #pythonbeginners
Apologies to everyone, the stream really struggled on the day which resulted in poor video quality. I had to re-upload just the audio.
😊 Ania Kubow's YouTube Channel
youtube.com/aniakubow
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
😊 You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#LiveInterview #AniaKubow #JavaScript
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
🐘 More PHP tutorials from me:
youtube.com/watch?v=950lwujV3Mk&list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
😊 You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#PHPTutorial #Live #composer
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
🐍 More Python tutorials from me:
youtube.com/watch?v=OqAVcsLcob8&list=PLrIm-p2rpV0HTT5PWA8O2djcNN5ONx-df
😊You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#PythonTutorial #Live #PythonLive
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
🐍 More Python tutorials from me:
youtube.com/watch?v=OqAVcsLcob8&list=PLrIm-p2rpV0HTT5PWA8O2djcNN5ONx-df
😊You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#PythonTutorial #Live #PythonLive
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
😀 This video started an interesting conversation on Reddit: reddit.com/r/PHP/comments/g74rhn/2min_quick_tip_how_to_use_git_stash_in_phpstorm
🐘 2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
🐘 PHP Developer Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
😊You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#git #phpstorm #tutorial
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
😀 This video started an interesting conversation on Reddit: reddit.com/r/PHP/comments/g74rhn/2min_quick_tip_how_to_use_git_stash_in_phpstorm
🐘 2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
🐘 PHP Developer Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
😊You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#gitstash #phpstorm #tutorial
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
👨💻 The final code can be found on Github:
github.com/revalgovender/python-csv
🐍 More Python tutorials from me:
youtube.com/watch?v=OqAVcsLcob8&list=PLrIm-p2rpV0HTT5PWA8O2djcNN5ONx-df
😊You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#PythonTutorial #CsvManipulation #PythonCsvFile
Open your terminal and type the following command:
composer require tymon/jwt-auth:1.0.0-rc.5
I am not sure how stable this package is as of recording this video, but it will be fine for the purposes of this project. So be aware when using it in production.
To complete the installation, we need to run the following artisan command which comes with the package.
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
The command will have copied the configuration file. In this configuration file, we have access to various settings. For now, we are interested in the secret which will be used for signing our tokens. Notice it is referencing an env variable that does not exist.
We need to run the following
php artisan jwt:secret
This command will generate a key and add it to our env file. We now have the package installed. In the next video, we will use.
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
It seems counter intuitive, to remove this logic just because we don’t have a test for it, then write the test and add the logic back.
Wherever possible, I try to make my commits small and covered by tests. So ideally, I would not commit in this scenario until I have covered the error handling.
So let’s write a test for the error handling. We should just be able to copy from one the Post test.
We can take the data provider as well. Make sure to update the method to handle a User rather than a Post. Run the test. Everything should pass.
Watch the next video here:
youtu.be/wO31xRxVMxk
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Open up your version control panel. Go to your first commit, select the user table migration, the user factory and user model, right click and select “Apply these selected changes”. This will bring back these files as simple as that. If you are not using version control and deleted these files, you can grab them from github.
I am going to add the User table fields as constants to the User Model, as we did with the Post model. Then I will update all strings to use these constants. I will just skip ahead to save time.
The reason we need the concept of users in our project is: Our endpoints are going to be restricted to the public. So our system will need to identify users to see if they are authenticated or not.
This means, we will first need a way to create a user. Let’s start by creating a test for creating a user. Go to your test directory and create a new folder for User. Now create a test file.
I am just going to copy everything from the Create Post then modify it. We are going to use Faker to setup a user, then hit an endpoint for user. Then assert that we see the new record.
If we run the test it should fail. So let’s add the route and the controller. Let’s modify the controller to handle a user. Run your test again, this time it should pass.
Watch the next video here:
youtu.be/B-iKM64Tc8M
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Open up your PostController and navigate to your index() method. Instead of grabbing all the records, we can use Laravel’s paginate method. Let’s set the per page to 3, we only want the title and content attributes and we want to be an array.
Now, you might be asking why are we changing code without writing a test first. To be honest with you, I don’t know the exact structure of what will come back from this method. In order to find out what the possibilities are, I am happy to explore the method a bit further before deciding on whether I want to go down this route.
What we should do now is: write/modify a test which could play into this scenario. Open up your IndexCest file.
Let’s bump the number of records up to 13. If we run our test, we should be able to see what comes back from the method. So the method produces exactly what we want. It has our data, but also has the links we want. We can use these links to navigate the pages of Posts.
Back in our test, I am going to use some magic to update the expected array. Ok, so a better way of making our assertion is to not use the assertEquals. Instead we can use “seeResponseContainsJson”. Which will grab the response for us and convert it.
Now, let’s run our test, it should pass. Yes, it does.
Watch next video here:
youtu.be/TaenizwQ4hY
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
☕️ You can buy me a coffee by supporting this video on Patreon:
patreon.com/revalgovender
😊You can find me here:
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
#gitflow #commands #tutorial
youtu.be/8XbKxQYfMWU
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
youtu.be/OREAtwyp2rA
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
We just need to send a post request to the Post endpoint then assert against the http response code coming back.
In our PostController, we just need to wrap the code in a try block. In our catch, we can use our new method to return the error response.
We need to then throw the exception, we can just check to see if the ORM found anything by using the isEmpty method.
If we run our test again, it should pass. Remember to run the entire test suite.
Watch next video here:
youtu.be/JsVGqyZbCdY
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Let’s open up our ShowCest file. There test can be called itWillReturn404WhenRecordCannotBeFound().
Let’s send a GET request with a random id. Run the test. Looks like we get back an HTML response. We can see in this response, the code is failing. Let’s make the test pass.
We need to open up our PostController and navigate to our show method. Inside the show method, we can wrap the code in a try catch block.
If we can’t find the record, we can throw an exception. So we need a response for the error.
Let’s run our test, it should pass and it does. Now have you noticed, we will be showing error responses in multiple places. Let’s refactor this line into its own method.
You might be wondering, why we are not writing a test first. It is because: the logic will be covered by our tests already. So let’s use PhpStorm to perform the refactoring for us. It will detect other code fragments for us too.
Remember to run your entire test suite. Everything passes.
Watch the next video here:
youtu.be/XBXvrWHZLqI
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
We know we are only testing against the Title Attribute. This is where Codeception Data providers come into play.
We can declare our Data Provider as an assertion above our test. We are basically declaring what method we will be using as our data provider. The method will return an array of arrays.
We can then pass this into our test. We will replace the existing constant with the data coming back from our data provider.
When we run our tests, Codeception thinks it has multiple tests rather than the one test we have.
Watch the next video here:
youtu.be/Je224_lLSsY
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
The code will fail and throw an error but we don’t handle that error.
So let’s write a test in our StoreCest test file. When we have an invalid parameter in our request, the server must respond with a 400 error. So let’s write a test for that.
A good name for this test can be, “itWillReturn400WhenMissingRequiredParameter()”.
Our test should fail, because we are not handling any errors in the controller. Let’s change that.
Open your controller and navigate to the store method. Let’s use Laravel’s manual validator to make the Title field required. We know without this field, we cannot save a record to the database.
So what we need to do next is wrap most of this method in a try/catch block. So if there are any failures, we can handle it. The Laravel validator, will let us know if the validation has failed. If it has failed, we need to throw an exception. We can declare the message and the http status code.
Our catch block, will then return a response using the same http status code as well as the message. Now our test should pass. Run your tests. Great it passes. Good work.
Watch the next video in this series here:
youtu.be/iIrrrUCAM1w
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Let’s check our tests. You know, this is part of owning and maintaining a code base is. We might add something for the benefit of the code base but not go about it the right way. That’s not ideal, but in our scenario, we have tests to cover any changes we make. We also have time to maintain our codebase. So when we are refactoring, we must be confident our tests will catch our bugs.However, tests are only as good as you write them to be. So when you write a test, think about what you are testing and ask yourself: Does your test actually cover that scenario.
Check migration, factory, controller. After those changes, let’s run our test suite to make sure everything still works as expected. I can’t stress how important it is to keep doing this. Keep your code cycles small. Same with your commits. Let’s commit this work.
Another important lesson to learn is, don’t keep dead code in a database. You are much better off removing stuff you don’t need. Let’s start with this controller. We can remove the create() and edit() methods.
We can also get rid of our User model and we can also get rid our User factory. Run your test suite. As expected, everything passes.
Watch next video here:
youtu.be/ugy6MEeeVWI
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
We need to have a record in the database to update, so we can leave the have() call in place. We then need to declare the data we want to use to update the record. We need Faker for this. Let’s declare an “updates” array. In this array, we can use the model field constants again as well as Faker.
The update endpoint, will return the record after the updates have been made to it. So we need an expected array here for the assertions. Let’s see if we can copy this from the Show test.
We then need to send a PUT request to the endpoint with an id and the data we want to use to update the record with. We have to grab the response to assert against.
Finally, we should assert against the 200 code, the response we get back as well as read the database to see if the table has been updated.
Let’s run our test. We should get a failure. Now, let’s write the code in our controller.
In here, we need to query the database for a Post record using the id given in the request. We then can set the attributes of the model to the data coming from the request. Perform a save() to write the data to the database. We can then return an array of data.
Let’s run our tests again. Everything should pass.
Watch next video here:
youtu.be/ngW5raXk6mA
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
In my experience, when pair programming, there have been instances where we have run out time. So we were working on my machine and I needed to jump onto something else or jump into a meeting. My colleague, still had time to work on the feature/bug, but all the work we had completed in the last hour, was on my machine. We created a path file and I just sent it to him. My colleague could then apply the patch to his machine and continue working.
So let’s try doing this here. Let’s remove the index() method. By checking our version control panel you can see we have changes in our working directory. Right click on your changes, click on create patch to clipboard. If we wanted to create a file, select the other option.
So we can demonstrate this, I am going to revert my changes in my working directory.
Press Ctrl + Shift + A or Cmd + Shift + A to bring up the actions menu. Search for “Apply Patch”. Hit “Enter”. Open up your working directory again. You will see you have a new changelist in here. This is our patch being applied. If we tried to commit, you can see we have our changes.
Reval Govender
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
PHP Developer Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
A Journey To TDD the tutorial series:
youtube.com/playlist?list=PLrIm-p2rpV0EWSkkE6Llxaw7sxnsxdVWB
☆☆ FOLLOW ME ONLINE ☆☆
LinkedIn: https://uk.linkedin.com/in/reval-gove...
Twitter: twitter.com/RevalGovender
☆☆ SPONSORSHIP ☆☆
Does your company want to sponsor a video? Contact me by twitter or LinkedIn
We need to create a record to delete, so we can keep this have(). We can get rid of the structure we created. We need to change to the action to Delete. We have to send the id of the record we wish to delete.
For our assertions, we need to use the assertion “dontSeeRecord”. Let’s run our tests, notice it will fail. Let’s update our controller method.
The delete process is very simple with Laravel. All we need to do is type Post::destroy($id);
For now, let’s return a success message.
The controller part of this action is really simple. We can use the destroy() method from Laravel to find and delete the record from the database. Let’s just return success as a string for now.
Let’s run our tests again. The should all pass. Good, they do. Don’t forget to run your full API test suite.
Watch next video here:
youtu.be/FtqmUuyNojE
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
We don’t need to create a post record here. What we need to do is: use Faker to generate data. Due to our table requiring data for most of the columns we specified in our migration, we are going to have to add the rest of our columns to our model. Let’s go to our model.
In our model, we are going to add the remaining fields. Open up your database panel to confirm the table structure or your migration. Let’s start adding the fields.
We then need to send a POST request with data for the new record we want to create. Finally, we need to change our assertion to seeRecord.
We also need to assert against the message in our response.
If we run out test now it will fail. Let’s update the controller to make this work.
We already have access to the request thanks to Laravel. Let’s create a new instance of our model. We now have to map each piece of data from our request to our model. Finally, we can save.
Let’s run our test again, hopefully everything passes. Ok good it does. Let’s know run our test suite. Good everything is still passing.
Watch next video here:
youtu.be/5o1z81mt2ds
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Go to your tests folder, copy your IndexCest file and paste it as ShowCest. Make sure you update the class name. Let’s update the name of this test to “itWillShowPostItem”.
Instead of writing this from scratch, let’s modify the test. We know we only need one record in the database for this to work, so change the multiple to have. We can get rid of the extra record.
We need to modify the request to send the id as a parameter.
Instead of running our entire suite. We can just run this test by right clicking and selecting run test. It will fail. We haven’t modified our standard laravel boilerplate yet. So let’s do that now.
Open up your PostController. Scroll down to the Show method. Laravel already knows we are going to send it an id. We can take this id and query the database. We can then take our structure from our test. Then return it.
Now let’s run out test again. Good, it passes. Now let’s run out entire suite. Good, it still passes.
I noticed something we could tweak. Let’s just return the structure rather than saving it to a variable first. We don’t have to change our tests for this, because the output of the endpoints still remain the same. Let’s run our tests again. Cool our tests still passes.
This is what TDD is about. We can be confident our refactoring has worked because our tests prove the functionality is still the same as it was before making the changes. This is where we start to see real benefits in automated tests. They prevented me from having to manually test each endpoint.
Watch next video here:
youtu.be/-CVHLeQhkT8
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
PhpStorm can run these tests for us, which I find a lot easier, quicker and more useful than running the tests via the command line. Let’s see how we can do this. People working on a Mac, these steps might be slightly different, but they won’t differ too much where you can’t follow along.
Go to: File - Settings - Language and Frameworks - PHP- CLI interpreter. Click on the three dots on the far right of this dropdown. Add a new remote interpreter. Select Vagrant and PhpStorm should automatically detect your configuration.
Next click on “Add configuration”. Add a new Codeception configuration. Name the configuration whatever you like. You can also choose any test scope. I will be selecting Directory, this is because I only want to run the API test suite. You can pass in options like “--colours”, in the “Test Runner” options input field. Click “OK”. Now we can click the play button, and our tests will now run in our Vagrant box using PhpStorm.
In this panel, we can see the terminal output. Notice on the left hand side, if we expand this, we can see tests that ran and even their assertions. We can double click on these assertions or test, to take us directly to the line on which they appear.
Let’s make this test fail to see what happens. So you can see how terminal output can be hard to debug at times. Even when there is more colour. PhpStorm will identify the difference in the string. We even have a history log here.
Watch next video here:
youtu.be/A067g2-MUY4
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
The first thing we have to do is open our Post Controller. Our index method, is meant to return all Posts from our database.
So let’s grab all the Posts using our model. The collection of data being returned is very large. If you recall, in our test we specified a specific structure to be returned. We can copy this straight from our test.
We then need to return a response object, containing our data.
Once we run this test, it should pass. Now that we have a passing test, it means our code is doing what we expect of it. This provides confidence in the feature we just wrote.
We are referencing the table’s fields as strings in our array keys. Let’s refactor this to be constants in our model. We already have our test, which asserts against structure, so all we need to do this time, is to make the change. The benefit of refactoring the field names to the model is: If we change the field names, we can just change it one place. It also makes it easier to type when the autocomplete feature of our IDE comes into play.
Let’s open up our Post model to add our fields. Then go back to our controller and update the the array to use the constants. Let’s run our test again, it should pass. Good, it does.
Now let’s make the same change in our test and run it again. We could potentially do a better job with asserting the structure of the array but this will do for now. Let’s run our test again. Good it passes.
We have now completed our first bit of work driven by a test. Let’s commit our work.
Watch the next video:
youtu.be/RzEcHUoJGVA
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
We have an alias in our vagrant box, courtesy of Homestead, to run Codeception. Instead of writing “vendor/bin/codecept”, you can type “codecept”. Homestead provides other aliases too. You should check them out. For now, let’s rebuild our configuration. “codecept build”.
Now let’s go back to our test. We know we want our endpoint to return actual post data, but right now, our controller is empty. So let’s change our test. In order for our database to have post data, we need to insert it. Instead of using hard coded data, like fixtures or data files. We are going to use the factory we created earlier in this course.
In our arrange step: This is where we use our Post factory. We just need to reference the Post model and define how many records we would like to create. Codeception does everything else for us.
Next let’s add our expected array. We are actually define how we would like our endpoint to return our data. Again, TDD is keeping us on track, by forcing us to think about the result before we start coding.
We will then JSON encode our array because our API will be returning a JSON response.
After we make out GET request, we can grab the response.
We can then compare the two by asserting they are equal.
Watch next video:
youtu.be/N9JHEj589Cw
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Open up the test file we just created. Note: we have to import our ApiTester actor class. We have some boilerplate here with a sample test. Let’s try to hit our home page just to see if the configuration is working correctly.
Let’s view the home page in our browser. Default Laravel installations have the string “Laravel” in large on the home page. We can assert this string is available in the response.
Let’s “vs” into our vagrant box. Run “vendor/bin/codecept run api” to run all our tests in our API test suite. This is fine for now as we only have one test which should not take long to run.
Our test passes, which confirms we are all set up and ready to go. Our api is going to have an endpoint named “/post”. If we send a GET request to this endpoint, we will see all posts from the database. We don’t have anything as it stands. So the first thing I would like to create is the index endpoint. I would also like the endpoint to return 200.
We know what we want to create, so we write our test to reflect this intent. I write tests using the “Arrange, Act. Assert” pattern.
Open up your terminal. Let’s run our test. Run “vendor/bin/codecept run api”. Our test will fail. Let’s write the code to make our test pass.
To create our controller, type “php artisan make:controller Api/PostController -r”. So we have our controller. Laravel has included default boilerplate for REST methods.
Navigate to your API routes file. You can find it in the routes directory. Delete the default laravel routes. Add the following:
Route::apiResource('post', 'Api\PostController');
Run “php artisan route:list”. This will return a list of all available endpoints in our application. You can see, we have multiple endpoints. We are interested in the Post endpoints. Laravel has created everything for us.
Let’s run our test again.. Good it passes.
Watch new video:
youtu.be/XOlbxYirwmk
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Open your terminal and run “vendor/bin/codecept”. Look for the generate suite command. Now run “vendor/bin/codecept generate:suite api”. Notice, Codeception tells us our next steps. We need to define the configuration for this suite.
Open up the api.suite.yml. Codeception created our API helper class. We can ignore this for now. Next, we need to enable our modules. All configuration options are available in the Codeception Docs. Please have a read through it, so you understand what we are enabling here.
Before we continue. Let’s create our .env.testing file. It is worth creating a testing .env. This is so you can keep your configuration for the testing environment separate from your local development environment. I believe I need to update my APP_URL value. Now let’s copy this and rename it to .env.testing.
Let’s run “vendor/bin/codecept build”. We are doing this just to see if our configuration is correct.
If this command runs successfully, we can be assume our suite configuration is correct.
Watch next video here:
youtu.be/MGGuqr6iDH4
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Remember to commit your code from the previous video before starting this one. I have already committed my changes.
You can create the model manually, but I am going to use Artisan to do it for me. Open the terminal and type: “php artisan make:model Post”.
Let’s close the terminal and find our model. It will be located in the app folder. This is all we need for now.
We are going to create a factory for our model. Think of factories as a convenient way to input multiple records of data in your table on the fly. We can call factories when seeding data into the database or in our tests.
Now, let’s create our factory. Again, you can create this manually, but I am going to use Artisan. Back in the terminal, I am going to run “php artisan make:factory PostFactory -m Post”. You will see why we are passing in the name of the associate model in a second.
The factory will be located in: database - factories. The first parameter of the define method requires a model. This why we use the -m flag when running the command, so Artisan can put in our model for us. To complete our factory, open up the database using PhpStorm. Navigate to our Post table. You can see the structure of table here, so let’s complete the factory.
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel keeps migrations in: Database - Migrations. There are some default ones here. Our project won’t require these tables. We can delete these migrations.
Let’s open up our terminal and run “php artisan”. This will give you a list of commands available to us. We need the make migration command. Run “php artisan make:migration -h”. This will give us more information about this command. We need to run “php artisan make:migration create_posts_table”.
This is a good convention to adhere to. It explicitly states what the migration does. For some reason this command does take a while to complete.
We can now see our new migration in the migrations folder. Laravel has some boiler plate in here. Let’s expand it. We have access to the migration helper methods via the table object. We are going to use these methods, to define our columns.
When we create an up method, we must create a down method. All we would have to do, is drop the table, the migration would have created. Laravel has already added this as part of the boilerplate.
Before we test our migration, we need to check our .env file. Our .env file needs to be updated to the correct Database name and credentials.
To test our migration, let’s ssh into our virtual machine. We need to run the command: vagrant ssh. I have “vs” as an alias, so I will be using this from now on. We need to cd into our code directory.
This time, let’s run “php artisan migrate”. This will run our migration for us to create our table. We can confirm the table has been created using PhpStorm.
Watch next video:
youtu.be/BRVdRTFsx7U
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
We can commit our changes, using Ctrl + K. Wherever possible, I am going to be using shortcuts. I will let you know what they are, the first time I use them.
Now, let’s install Codeception. To install codeception, run the composer command:
“composer require codeception/codeception --dev”. The “--dev” flag will save Codeception as a dev requirement in our composer.json file. To speed up the download process, I will just skip ahead.
If we take a look in our project view, we can see our composer.json and composer.lock file has been updated. Let’s open up our composer.json. You can see Codeception has been added as a dev dependency.
Before we initialise Codeception. Let’s take a look at our Tests folder. We have some default Laravel stuff in here. Let’s get rid of it, to keep this folder clean. When we boootstrap Codeception, it will create new files here.
To bootstrap Codeception, open up the terminal. To save time, do this outside of Vagrant. Whenever you can do something, outside of the virtual machine, take the opportunity to do so. Whenever we run operations within the virtual machine, it is always going to be slower than out.
Run “vendor/bin/codecept”. This will give us a list of available commands. We want to use the Bootstrap command. So let’s run “vendor/bin/codecept bootstrap”. This will generate new files and folders in our test directory.
Let’s take a look. We now have Codeception installed and initialised. Let’s commit our work.
Watch next video:
youtu.be/JWW4r1xM4Q4
Watch this course in full here:
youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB


