Nathan-Al / MyMenu

Gestionnaire de Menu pour entreprise
0 stars 1 forks source link

Fixture factories #7

Open pabloelcolombiano opened 2 years ago

pabloelcolombiano commented 2 years ago

Hello there,

I saw in your tests that you might be having issue using the fixture factories. Let me know if I can assist you to put this in place!

Nathan-Al commented 2 years ago

Hello there,

I saw in your tests that you might be having issue using the fixture factories. Let me know if I can assist you to put this in place!

Hello, if it's good with you it will be my pleasure !

pabloelcolombiano commented 2 years ago

Sure. What was the issue you encountered?

Nathan-Al commented 2 years ago

Sure. What was the issue you encountered?

Well i was trying to use the fixture Factory to mock the data in my database, but when i read the doc i understand that the way CakePHP used the Fixture i would need a test database. So after that i tried to do the fixture myself a tried it with FixtureFactory. It worked for one of my table but not the other, even with the fact that i did the same thing. Do it actually possible to mock the database with Fixture Factory ? Thank for your time.

pabloelcolombiano commented 2 years ago

There is no "mocking of the database" as such.

  1. You first need a test database, and set it up as described here. This is no mocking, it is a second database, identical to the productive one, but dedicated to the tests.
  2. Once this is done, you can write your tests. If this worked with one factory, there is no reason it should not work with the second (and the third, etc)

If you have an error message or something to help debugging, let me know, I'll try to help you.

Nathan-Al commented 2 years ago

There is no "mocking of the database" as such.

  1. You first need a test database, and set it up as described here. This is no mocking, it is a second database, identical to the productive one, but dedicated to the tests.
  2. Once this is done, you can write your tests. If this worked with one factory, there is no reason it should not work with the second (and the third, etc)

If you have an error message or something to help debugging, let me know, I'll try to help you.

Hello, thank for the quick answer. It's a shame that mock dosen't exist but well. Guess i need to find another way to do the test with Ghitub actions. I'm not really sure why the second test didn't work, at first CakePHP tell me that he was searching a tables en the test database but with a extra s. My table name is "produit" but CakePHP search "produits" so he can't find it. I almost forget one of the most troublesome problem, dosen't the fixture create the table, insert the test datas, and clear everything after the test ? Because for me he only insert the datas. That's all.

Thank for your time

pabloelcolombiano commented 2 years ago
  1. Mocking the database is not desired - you want to test the queries you've written. E.g. DELETE FROM users WHERE deleted = 1; has a different impact as DELETE FROM users;. So no, it is not a shame ;-)
  2. I highly recommend you to follow the CakePHP naming conventions, by naming your tables in English plural. Though this is not a requirement, it will facilitate your development experience. If you must stick to french singular table names, I would need more input on the error triggered to help you. This might well not be related to the factories.
  3. The fixture factories do not create the tables, nor clear anything in the DB. It does insert test data, if persistence is demanded.
  4. The management of the schema (crating the tables) is handled by the Migrator (either from vierge-noire if CakePHP<4.3, or from Cake if CakePHP >4.3). If you have installed the test suite light, the dirty tables get cleared before each test, and not after.
Nathan-Al commented 2 years ago
  1. Mocking the database is not desired - you want to test the queries you've written. E.g. DELETE FROM users WHERE deleted = 1; has a different impact as DELETE FROM users;. So no, it is not a shame ;-)
  2. I highly recommend you to follow the CakePHP naming conventions, by naming your tables in English plural. Though this is not a requirement, it will facilitate your development experience. If you must stick to french singular table names, I would need more input on the error triggered to help you. This might well not be related to the factories.
  3. The fixture factories do not create the tables, nor clear anything in the DB. It does insert test data, if persistence is demanded.
  4. The management of the schema (crating the tables) is handled by the Migrator (either from vierge-noire if CakePHP<4.3, or from Cake if CakePHP >4.3). If you have installed the test suite light, the dirty tables get cleared before each test, and not after.

Hello,

  1. Yeah i understand the concept it just... well nothing.
  2. Well the database is not definitive, the project is really just a test for now. For the error i can't really show it to you right now, but when i have the time i definitely do it thank.
  3. Thank for the clarification, it's seem that i didn't understand how the fixture actually worked.
  4. I didn't know i had to install that too.