13. PHP Unit testing tutorial and pages list | Automated testing with PHPUnit | CMS OOP tutorial MVC

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024

ความคิดเห็น • 56

  • @gamerszone7592
    @gamerszone7592 2 ปีที่แล้ว +2

    one of the best teachers in the world respect ❤ thank you so much ❤️

  • @Rtzoor
    @Rtzoor 3 ปีที่แล้ว +3

    thank you for all the effort you put into these videos! it's clear they are well thought out. I am trying to learn PHPUnit, and unit testing in general, to start using it in my workplace.

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว

      Thank you Tzoor for you kind words, that is nice to hear. What do you think unit testing will solve for you?

  • @AlbertAngmor
    @AlbertAngmor 2 ปีที่แล้ว +1

    the effort you put into your videos is clear. I am actually learning a lot from you. Now I am off to get your course

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว

      Thank you very much Albert, your support is highly appreciated. Welcome to the course :)

  • @phixphixation7261
    @phixphixation7261 2 ปีที่แล้ว

    Thank you for this excellent in depth course, I have watched everything so far. This video has been especially helpful, I have not used testing before, it is indeed a great helper.

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      Glad it was helpful! I use test sporadically I must admit. The way I see it, it is another tool in our toolset at the end of the day. Do you write your code in a team, or mostly alone?

    • @phixphixation7261
      @phixphixation7261 2 ปีที่แล้ว +1

      @@ApplicableProgramming I write everything myself. Since a couple of months I am getting back into PHP, it has been 3 years before that since I was last working on a CMS. I tend to want to write everything myself, I know this is not very recommended, but very interesting though.

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      @@phixphixation7261 It is definitively a good way of learning A LOT of internal principles, how things work. Then when you one day want, or have to use some framework or library, you will know all principles behind the tools you are using.
      What else are you working with?

    • @phixphixation7261
      @phixphixation7261 2 ปีที่แล้ว

      @@ApplicableProgramming I like to use UML to give myself a visual overview, and not make it too complex, simple is better, the key is to reduce complexity. An image can say more then a 1000 words. I also tend to use Illustrator to create visualizations for abstract logic and concepts, especially OOP-based that can be represented in the real world.

  • @Raezon_
    @Raezon_ 3 ปีที่แล้ว +1

    really amazing

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว

      Thank you Ammar, glad you liked it :)
      Are you following entire CMS series?

    • @Raezon_
      @Raezon_ 3 ปีที่แล้ว

      @@ApplicableProgramming not yet but i attend to follow it soon

    • @Raezon_
      @Raezon_ 3 ปีที่แล้ว +1

      after watching your video I get inspired for writing a unit test for Bi reporting, so if I have a transaction I m supposed to see :
      if no transaction
      $this->assertEquals($arrayResultQueries[, []);
      if transaction
      $this->assertGreaterThan(0, count($arrayResultQueries]));

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว

      @@Raezon_ That is great, start with the least "interesting" case, and that is automatically better then no case at all :)

  • @b4rt1j1
    @b4rt1j1 2 ปีที่แล้ว +1

    Hi, This is the first time Im learning testing with PHP Unit, thank you for awesome introduction.
    By the way optional parameter mode in fetch PDO statement (PDO::FETCH_OBJ) can help us fetch the data from database in proper format so we dont have to make objects from the array and can save few lines of code I think.

    • @ApplicableProgramming
      @ApplicableProgramming  2 ปีที่แล้ว +1

      That is an awesome tip! To be honest, I do not remember when was the last time I haven't used any framework and worked directly with database (outside the tutorials), so yeah... a lot of things have changed since :)

  • @saumyaranjanpani9214
    @saumyaranjanpani9214 3 ปีที่แล้ว +1

    Please make more beginner project on mvc
    Btw vdo is cool 👍

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว +1

      Thanks Saumya. I will start on the new video next week, so suddenly it comes :)
      Have you been following the entire series?

    • @saumyaranjanpani9214
      @saumyaranjanpani9214 3 ปีที่แล้ว

      @@ApplicableProgramming yeah

  • @HarryNewman-j8m
    @HarryNewman-j8m ปีที่แล้ว +1

    Do you use an extension to format your var_dumps to be more readable? My arrays just get printed as one long ugly string.

    • @ApplicableProgramming
      @ApplicableProgramming  ปีที่แล้ว

      Great question. I always used some tool that either comes with the framework, or I just install Monolog, or some variation of dump function. I had some of my own helper functions that will wrap text in PRE tags, but that I use rarely latelly.
      var_dump is just always available so I showed it in this tutorial to avoid explaining how to add it. And yeah, it is ugly as it gets :)

  • @vilhemleshi7222
    @vilhemleshi7222 ปีที่แล้ว +2

    I am interested into PHP Unit testing Course.

    • @ApplicableProgramming
      @ApplicableProgramming  ปีที่แล้ว +1

      GReat, I am sketching the course, are you willing to participate in its creation maybe? I can guide you, and you can share your progress with me so that we both learn. Can you reach out to me via discord, the link is on the channel page or applicableprogramming.com ?

  • @aleenshrestha8119
    @aleenshrestha8119 3 ปีที่แล้ว +1

    File not found error while including class file in unit tests

  • @arunkumark1596
    @arunkumark1596 3 ปีที่แล้ว +1

    Thank you for your wonderful and professional tutorial. I was able to understand the true oop php concept after watching tutorial series. Please continue the good work.

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว

      Ah you are too kind Arunkumar K, glad it helped :)

    • @arunkumark1596
      @arunkumark1596 3 ปีที่แล้ว +1

      @@ApplicableProgramming When is the next class 15 is coming.

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว

      @@arunkumark1596 That is an excellent question Arunkumar... I am on vacation now, but am still working here and there. I suspect in few weeks at least, I am yet to figure out what the video will be about. It will partly be about updating values in database, but do you have some more suggestions what you would like to see?

    • @arunkumark1596
      @arunkumark1596 3 ปีที่แล้ว +1

      @@ApplicableProgramming Well, i would like to know how to integrate and use composer packages like doctrine in this project. Waiting for more of your tutorials.

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว +1

      @@arunkumark1596 Great suggestion, I will cover Composer in the next video

  • @zakelijkvoordeel5437
    @zakelijkvoordeel5437 3 ปีที่แล้ว +1

    I did the homework. I made a new page: page-editor, with the following URL: index.php?module=edit&action=edit&page=home. As you can see I added to the dashboardController the method editAction, which loads the findAll with title and content from the database and renders the page-editor with the template engine and pageTitle in the $variables. At the editor page I retrieve the page to edit from the URL and use the foreach and if statement to show the data.
    $pageTitle = trim($_GET['page']);
    Between the textarea tags from the editor:
    foreach ($pages as $page) {
    if($page->title === $pageTitle) {
    echo $page->content;
    }
    }
    It works fine now for every page, except I can't do anything with it. So to save it in the database I do have to add another case to the switch statement, like update and create an update method in the controller. Or with future db handlings in mind I should make a new controller for updating fields in the database dynamically. After succesfull updating the database it returns the user (admin) to the updated page.
    Also when logged in the user can view the frontside with some extra buttons like edit page directly.
    I am curious how you solve it, when does your next video come out?
    thanks in advance and good luck with the video's.

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว

      Your comment was again stuck in spam for days, now it should be out. I like the idea of universal controller for crud, however I never built it that way, I would just add a "update"action to every module. Reason being that sometimes there is need for manual changing the data on the way to database. However there are frameworks that do what you mentioned, they have a special "crud" controller that they extend, and that crud controlled adds typical C.R.U.D. methods. If that sounds interesting you could go in that direction to pay, but you can also just make one "update"method in active record, and one case in controller. Make sure that active record update method is universal for all models (you could even write small tests for it to test on different models). Have you tried writing tests?

    • @zakelijkvoordeel5437
      @zakelijkvoordeel5437 3 ปีที่แล้ว

      @@ApplicableProgramming Yes, before creating new classes/methods the first thing I do is creating a test for what it should do. I know the frameworks which do it that way but the work I put in this CMS to secure against XSS and session hijacking, also different levels of users. The dashboard shows the newly created scripts, productivity(percentage), worked hours and the total amount to payout depending on the hours worked. (in case of freelance or external copywriters/programmers). Also with the payout it's possible to click on create invoice and it builds an user depending invoice. So for now I don't integrate it in an existing framework. With composer I added a few packages like PHPMailer (not yet implemented).
      first I want to make it a working CMS by completely manipulate the database on the backend so I can build the frontend the usual way (in a CMS).
      I will upload it in a private github repo when I do have the time. I do think I will make an abstract CRUD controller to extend for now.
      Do you have any idea when your next video comes out? Thanks in advance!

    • @zakelijkvoordeel5437
      @zakelijkvoordeel5437 3 ปีที่แล้ว +1

      When I try to update the database with the new content, i do have the following code:
      $sql = "UPDATE pages SET content = :content WHERE title=$pageTitle";
      $stmt = $dbc->prepare($sql);
      $stmt->execute(["content" => $newContent]);
      But when I try to save the content of the editor, I get the following error:
      UPDATE pages SET content = :content WHERE title=home
      SQLSTATE[42S22]: Column not found: 1054 Unknown column 'home' in 'where clause'
      A little bit strange because it can load the data from that same table with the same $pageTitle = $_GET['section']; How comes it thinks home is the column instead of title?

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว +1

      @@zakelijkvoordeel5437 this is the clue WHERE title=$pageTitle
      best it to prepare the :title the same way you did with the contetn = :content
      If it is not prepared, and if not quoted, then mysql will take it as a column name (variable). Can you make this method to be universal for all entities, not just for pages?

    • @zakelijkvoordeel5437
      @zakelijkvoordeel5437 3 ปีที่แล้ว +1

      @@ApplicableProgramming Yes, thankyou problem solved:
      $sql = "UPDATE pages SET content=:content WHERE title=:title";
      $preparedFields = ([
      'content' => $newContent,
      'title' => $pageTitle ]);
      $stmt = $dbc->prepare($sql);
      $stmt->execute($preparedFields);
      after successfully updating a page, it redirects to the page on the frontside to show the adjustments!
      Thanks a lot!

  • @dasuneranda
    @dasuneranda 3 ปีที่แล้ว +1

    Your are teaching very well..

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว +1

      Thank you for nice words Semicolon CG.
      Btw, do you use Unit Test in your projects?

    • @dasuneranda
      @dasuneranda 3 ปีที่แล้ว +1

      @@ApplicableProgramming frankly I'm not..I'm trying to add it future project's

    • @ApplicableProgramming
      @ApplicableProgramming  3 ปีที่แล้ว +1

      @@dasuneranda What do you think it will help you with? (also if I may ask , are you following the entire tutorial or just found this video?)

    • @dasuneranda
      @dasuneranda 3 ปีที่แล้ว +1

      @@ApplicableProgramming yeah of causes. , And I searched for Laravel testing