1. Home
  2. Explore
  3. Computer Science
  4. Installing PHPUnit with Composer

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Installing PHPUnit with Composer

  • 44Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Installation and Configuration
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

How can PHPUnit be installed as a development-only Composer dependency?

Tap to flipClick to flipspace

Run composer require --dev phpunit/phpunit or confirm Composer’s prompt to install it as a development dependency.

Or swipe the card

44 cards

  1. How can PHPUnit be installed as a development-only Composer dependency?

    Run composer require --dev phpunit/phpunit or confirm Composer’s prompt to install it as a development dependency.

  2. Why is PHPUnit generally installed as a development dependency rather than a production dependency?

    Unit tests are normally run during development, so PHPUnit does not need to be installed on the production server.

  3. Where does Composer record development-only dependencies?

    In the require-dev section of composer.json.

  4. What is the purpose of the bootstrap setting in a PHPUnit XML configuration?

    It specifies a file PHPUnit loads before running tests.

  5. Why can a PHPUnit configuration use vendor/autoload.php as its bootstrap file?

    It loads Composer’s autoloader so project classes and other autoloaded files are available to tests.

  6. What is the purpose of enabling PHPUnit’s colors configuration option?

    It makes test results easier to read by displaying outcomes, such as passing and failing tests, in color.

  7. What does a PHPUnit test suite configuration specify?

    It gives a test suite a name and identifies the directory containing its tests.

  8. How can a PHPUnit XML configuration specify which production source files to include?

    Configure the source directory, such as src, and include files matching a pattern such as *.php.

  9. Which PHPUnit configuration file takes precedence: phpunit.xml or phpunit.xml.dist?

    phpunit.xml takes precedence; PHPUnit falls back to phpunit.xml.dist if the first file is absent.

  10. Where does PHPUnit store its generated test cache, and why might that cache be ignored by Git?

    It stores the cache in the configured cache directory, such as .phpunit.cache; the cache can be ignored because it is generated locally.

  11. What directory convention is used for unit tests in the described project?

    Place them in a plural tests directory, with subdirectories that reflect the code being tested.

  12. How is a test namespace commonly organized in relation to the project namespace?

    Use the project’s namespace as a base, then add a test namespace segment and the relevant subnamespace.

  13. What naming convention identifies a PHPUnit test class for a User class?

    Name it UserTest.

  14. What naming convention identifies a test method in the described PHPUnit style?

    Use a public method whose name begins with test, such as testSequentialId.

  15. Why might a test method declare a void return type?

    Because the method performs assertions and does not return a value.

  16. Why is a PHPUnit test class often declared final?

    To prevent other classes from extending it, since test-class inheritance is usually unnecessary.

  17. What effect does declare(strict_types=1) have in a PHP test file?

    It makes PHP enforce declared scalar types strictly rather than silently coercing incompatible values.

  18. Which PHPUnit class should a test class extend to use PHPUnit’s test features and assertions?

    PHPUnit\Framework\TestCase.

  19. What is the role of the setUp method in a PHPUnit test class?

    It prepares shared state or objects before each test runs.

  20. Why should an overridden PHPUnit setUp method call parent::setUp()?

    To preserve any setup performed by PHPUnit’s parent test-case implementation.

  21. How can a test class reuse the same kind of object across its test methods while keeping tests isolated?

    Declare a property for the object and initialize a fresh instance in setUp before each test.

  22. Why should a test import the production class it exercises?

    So the test can refer to and instantiate the class using its fully qualified namespace.

  23. What does PHPUnit’s assertSame check?

    That the expected and actual values are identical in both value and type, equivalent to PHP’s === comparison.

  24. In what order should expected and actual values be passed to assertSame?

    Pass the expected value first and the actual value second.

  25. How can a test verify that a setter stores a sequential ID correctly?

    Set a known ID on the entity, then use assertSame to compare that ID with the value returned by the getter.

  26. How can a test verify that a user entity stores and returns a UUID?

    Set a UUID string on the entity and use assertSame to compare it with the value returned by the UUID getter.

  27. Why does the described Ramsey UUID usage call toString() on a generated UUID?

    The UUID generator returns an object; toString() converts it to the string value expected by the entity.

  28. How can PHPUnit run only one test method using a filter?

    Use the test class name followed by :: and the test method name in the filter, such as UserTest::testOnSerialize.

  29. How can PHPUnit be run when it is installed locally through Composer rather than globally?

    Run the project’s vendor/bin/phpunit executable.

  30. Which executable can be used to run PHPUnit if it has been installed globally?

    Run phpunit from the terminal.

  31. What does a serialization test for a user entity verify?

    That data passed to the entity’s unserialization method can be retrieved through the corresponding getters.

  32. Which user ID field should a user entity serialization test verify?

    Verify the input id using the entity’s sequential-ID getter.

  33. Which UUID field should a user entity serialization test verify?

    Verify the input user_uuid using the entity’s UUID getter.

  34. Which name fields should a user entity serialization test verify?

    Verify first_name with the first-name getter and last_name with the last-name getter.

  35. Which contact fields should a user entity serialization test verify?

    Verify email with the email getter and phone with the phone getter.

  36. Which credential field should a user entity serialization test verify?

    Verify password using the entity’s password getter.

  37. Which date field should a user entity serialization test verify?

    Verify created_date using the entity’s creation-date getter.

  38. Why should a test avoid asserting on session-token fields that the entity does not yet retrieve?

    Because testing those fields is not meaningful until the entity implements their retrieval.

  39. What is the purpose of export-ignore entries in a .gitattributes file?

    They exclude specified files or directories from Git-generated archives, such as downloadable package archives.

  40. How do .gitignore and .gitattributes export-ignore entries differ?

    .gitignore controls which untracked files Git ignores; export-ignore controls which tracked paths are omitted from exported archives.

  41. Why might a library exclude its tests directory from a Composer-distributed archive?

    Tests are usually development files and may be unnecessary in the installed package.

  42. Why might a project ignore the .phpunit.cache directory?

    It is generated test-run data and does not need to be committed as source code.

  43. Why might a project avoid committing a customized phpunit.xml file?

    It may contain local configuration, while the shared phpunit.xml.dist can provide the project’s default settings.

  44. What is a sensible workflow before committing changes to unit tests?

    Run the test suite and confirm that the tests pass before committing.

Card 1 of 44
Card 1 of 44

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent