• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing CRUD operations

#1
Hello All !

I am learning about PhpUnit and Php testing.

I tried to find some documentation about testing CRUD operations but I couldn't find anything related to CI.

I believe that the "problem" is that testing CRUD is a integration test, right ?

A basic "script" for testing a Add (POST) operation would be:

1 -> Send a Post request with data to a URL
2 -> Check if the return is right
3 -> Check if the record was inserted into the database

Let's start with the first step:

Question: What is the best way to send POST data from PHP for testing ? Does CI have something to help us with this ?
Reply

#2
CI4 does have something to help you. There's probably some features that are missing but it's should cover your basic needs.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#3
Awesome !

Thank you my friend !

I got that working !

Now, is there a way to easily check if the recorded was inserted into the database ?

Do you believe that we should be testing for something else in a basic CRUD operation ?
Reply

#4
There's a number of database testing methods. You might want to peruse the testing portion of the docs a bit more...

PHP Code:
$this->seeInDatabase('table', ['foo' => 'bar']); 

You should check both success and failure conditions, like when the wrong type of data was sent, etc. Test any edge cases you can think of, etc. However, just getting the basic success/fail conditions tested on those goes a long way when you're building your app out to make sure you don't break things.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#5
(10-30-2019, 08:16 PM)kilishan Wrote: There's a number of database testing methods. You might want to peruse the testing portion of the docs a bit more...

PHP Code:
$this->seeInDatabase('table', ['foo' => 'bar']); 

You should check both success and failure conditions, like when the wrong type of data was sent, etc. Test any edge cases you can think of, etc. However, just getting the basic success/fail conditions tested on those goes a long way when you're building your app out to make sure you don't break things.

Thank you Sir !

BTW, I miss your posts in your patreon page ... The last one was 2 months ago ! It would be awesome to see some CI testing there....

Specially on how to make all system tests PASS... haHaha

Also, I am playing around with project-tests. https://github.com/codeigniter4projects/project-tests
Reply

#6
MGatner did a great job with the project tests repo. That's what Myth:Auth is using currently (though I'm in the middle of trying to beef up tests on that).

RE: Patreon - I know! And I feel horrible. In the middle of recording some, actually, so will have some very soon.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#7
(10-30-2019, 08:40 PM)kilishan Wrote: MGatner did a great job with the project tests repo. That's what Myth:Auth is using currently (though I'm in the middle of trying to beef up tests on that).

RE: Patreon - I know! And I feel horrible. In the middle of recording some, actually, so will have some very soon.

Great to know that Myth:Auth is using that ! I will take a look and use it as a example ! I love to learn from practical examples...

About Patreon - Don't fell bad about it ! We all know that you are working hard and spending a lot of time in Myth:Auth !

Btw, do you believe that you will have a stable release anytime soon ? I wanted to use it in my current project but, I got scared with:


Quote:NOTE: This package is under early development and is not ready for prime-time.

Big Grin
Reply

#8
I put that note up there when it was in the middle of being ported from older codes a while back and just haven't taken it down yet, since we haven't hit a final release, yet. It's in a beta release, though.

Myth:Auth is very close to ready. A couple of people are already using it in projects. I don't expect any breaking changes to happen. Well - except one that I found a couple of nights ago doing testing that deals with where user-specific permissions are stored. Well - the api for that doesn't change, but it seems there's two locations it could store it currently so I need to whittle that down to one. Smile
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#9
(10-31-2019, 06:27 AM)kilishan Wrote: I put that note up there when it was in the middle of being ported from older codes a while back and just haven't taken it down yet, since we haven't hit a final release, yet. It's in a beta release, though.

Myth:Auth is very close to ready. A couple of people are already using it in projects. I don't expect any breaking changes to happen. Well - except one that I found a couple of nights ago doing testing that deals with where user-specific permissions are stored. Well - the api for that doesn't change, but it seems there's two locations it could store it currently so I need to whittle that down to one. Smile

Really ??? Consider yourself forgiven for not posting in Patreon !  Heart Heart Heart ... and Please remove that statement that keeps people far away from Myth Auth....

Angel  ... I will create a new Support post if I have any questions... And please, don´t be mad if the are newbie questions... I am note afraid of asking the Jedi Masters when I am not 100% sure...
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.