dockeranddocker composemust be installed to use this template- you must have basic knowledge of PHP
git clone https://github.com/deozza/php-oop-exercicescd php-oop-exercicesdocker compose up -d --builddocker compose exec php-oop-course composer install
Check that your installation was successful by executing :
docker compose exec php-oop-course ./vendor/bin/phpunit ./tests/DummyTest.phpYou should have the following result :
PHPUnit 11.3.1 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.22
. 1 / 1 (100%)
Time: 00:00.009, Memory: 6.00 MB
OK (1 test, 1 assertion)This repository is based on TDD. Tests asserting you have answered correctly are already written. You can assume you have answered as you should have by executing the tests and none of them are failing.
In order to use this system, you will need to follow closely the instructions of each exercice. This is also true for naming your folders, your files, your classes, etc.
All your code must be located in the app/src folder.
If you want to check your code manually, you could use the app/src/index.php file and use your code inside.
You can then use the following command to execute the code in this file :
docker compose exec php-oop-course php -f src/index.phpYou can also open your browser and navigate to the 127.0.0.1:8080/src/index.php to check your code.
If you want to check you have completed that exercice, use the following command :
docker compose exec php-oop-course ./vendor/bin/phpunit tests/Exercice3If you want to check you have completed all the exercices, use the following command :
docker compose exec php-oop-course ./vendor/bin/phpunit testsCreate a new class named
Product. You should be able to instanciate a new object of this class.
In your precedent class
Product, add the following properties
- name
- price
- dateOfRelease
Modify your precedent class
Productso its properties has default values :
- name : "New product"
- price : 9.99
- dateOfRelease : the date of today
In your precedent class
Product, change your properties so thatnamecould only be assigned characters,pricenumbers and decimals,dateOfReleasea date
In your precedent class
Product, add typedgetterandsetterfor each of the properties
In your precedent class
Product, find a way to return the name of the product with the first letter capitalized
Create a new class named
User. This class would have the properties :
- firstname
- lastname
- birthday
This class would have getter and setters for all its properties.
Then create another class named
DateCalculator. This class would have a method calledgetDaysBetweenTwoDates. It takes two dates and calculate number of days between them. For example, if the given dates are2024 October 31thand2024 October 26th, the method would return360.Then create another class named
BirthdayPlanner. This class would have a method calledgetNextBirthdayMessage. It takes a user as argument and would display the following message :Hello <firstname> <lastname> ! There are <numberOfDays> days until your next birthday..
Create a new class named
Square. This class would have a property namedlength, typed as a float. It would also have a setter and a getter. It would also have a methodgetAreato calculate and return the area.
Write a PHP CLI script. It would take as input the dimesion of a square. It would then echo the area of the square.
Create a new class named
Rectangle. This class would have a property namedlengthandwidth, typed as a float. It would also have a setter and a getter. It would also have a methodgetAreato calculate and return the area.
Adapt the CLI script to let the user chose between a square and a circle
Use polymorphism to simplify the CLI script. You will write an abstract class named
Shapewith an abstract methods calledgetArea,getDimensionsNamesandsetDimensions. Create a new class namedCircleand add it as a choice of the CLI script
Something to do with extends on user (for employee, client, secretary, ...)
Something to do with a login page
Implement form validator for the login page
Create a logger when login is unsuccessful. Make it a singleton
Create a db connexion
Make db requests for select, insert, update, delete
Make it into a ORM