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

  • 53Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: PHPUnit Setup
The package manager command used to add PHPUnit to a PHP project is
.

53 questions

  1. 1
    The package manager command used to add PHPUnit to a PHP project is
    _____
    .
    Hint

    Recall the command that adds a package and updates the project dependencies.

    Answer

    composer require phpunit/phpunit

  2. 2
    When Composer asks whether PHPUnit should be installed as a development dependency, the appropriate response is
    _____
    .
    Hint

    Consider whether a testing tool is needed on the production server.

    Answer

    yes

  3. 3
    Installing PHPUnit as a development dependency keeps it out of the project's
    _____
    dependencies.
    Hint

    These are the dependencies needed on the live server.

    Answer

    production

  4. 4
    The PHPUnit version installed in the example is
    _____
    .
    Hint

    It is the latest version identified in the example.

    Answer

    10.2.3

  5. 5
    The PHPUnit configuration file used as the starting point is
    _____
    .
    Hint

    It is the distribution version of the XML configuration file.

    Answer

    phpunit.xml.dist

  6. 6
    The configuration's bootstrap setting directly loads
    _____
    so Composer's autoloader can include project classes.
    Hint

    This file is generated by Composer and is also loaded by the project's entry point.

    Answer

    vendor/autoload.php

  7. 7
    The PHPUnit configuration option that makes test results appear in color is
    _____
    .
    Hint

    It controls whether test output is displayed in red and green.

    Answer

    colors

  8. 8
    The configuration section that groups tests to be run is called a
    _____
    .
    Hint

    It names and organizes a collection of tests.

    Answer

    test suite

  9. 9
    In the example configuration, the unit test suite looks for tests in the
    _____
    directory.
    Hint

    The directory name is plural in the example.

    Answer

    tests

  10. 10
    The source configuration includes PHP files with the
    _____
    extension from the source directory.
    Hint

    This is the standard extension for PHP source files.

    Answer

    .php

  11. 11
    The test directory convention used in the project is the plural directory named
    _____
    .
    Hint

    It is the directory name specified for the unit test suite.

    Answer

    tests

  12. 12
    A test class for the User entity is named
    _____
    to follow the PHPUnit naming convention.
    Hint

    The class name uses the entity name followed by the test suffix.

    Answer

    UserTest

  13. 13
    A PHPUnit test class should end with the suffix
    _____
    so it is identified as a test class.
    Hint

    It is appended to the name of the class being tested.

    Answer

    Test

  14. 14
    The example places the User entity test in the
    _____
    namespace beneath the project's test namespace.
    Hint

    It corresponds to the kind of project class being tested.

    Answer

    Entity

  15. 15
    To use the project class in a test, the test imports the
    _____
    class.
    Hint

    It is the entity whose getters and unserialization behavior are tested.

    Answer

    User

  16. 16
    The test class extends PHPUnit's
    _____
    base class to use its testing features and assertions.
    Hint

    This base class provides methods such as assertSame.

    Answer

    TestCase

  17. 17
    The project marks its test class as
    _____
    to prevent other classes from extending it.
    Hint

    This PHP keyword prohibits class inheritance.

    Answer

    final

  18. 18
    The declaration that makes PHP enforce declared types strictly is
    _____
    .
    Hint

    It is placed at the beginning of a PHP file and enables strict type behavior.

    Answer

    declare(strict_types=1)

  19. 19
    Under strict typing, a value of the wrong declared type causes a
    _____
    rather than being automatically cast.
    Hint

    Strict typing rejects the type instead of converting it.

    Answer

    fatal error

  20. 20
    A PHPUnit test method in the example is declared with the visibility
    _____
    .
    Hint

    PHPUnit must be able to discover and run the test method.

    Answer

    public

  21. 21
    The setup hook in a PHPUnit test class is named
    _____
    .
    Hint

    It runs before a test to prepare its initial state.

    Answer

    setUp

  22. 22
    The setup hook should call the
    _____
    implementation before performing its own initialization.
    Hint

    It is the setup method inherited from PHPUnit's base test class.

    Answer

    parent setup

  23. 23
    A test method that does not return a value is given the return type
    _____
    .
    Hint

    This type indicates that a function returns no value.

    Answer

    void

  24. 24
    The entity instance reused by the tests is created in the
    _____
    method.
    Hint

    This lifecycle method prepares the state before each test.

    Answer

    setUp

  25. 25
    The example stores the shared User entity in a
    _____
    property of the test class.
    Hint

    This visibility limits access to the property to the class itself.

    Answer

    private

  26. 26
    The assertion used to compare expected and actual values with strict type checking is
    _____
    .
    Hint

    It checks equality using the equivalent of PHP's three-equals operator.

    Answer

    assertSame

  27. 27
    PHP's strict comparison operator corresponds to
    _____
    .
    Hint

    It uses three equals signs rather than two.

    Answer

    ===

  28. 28
    The first getter behavior tested on the User entity is retrieval of the
    _____
    .
    Hint

    The example assigns it the value 55 before checking its getter.

    Answer

    sequential ID

  29. 29
    The expected sequential ID in the example's first getter test is
    _____
    .
    Hint

    It is the numeric value assigned before the strict assertion.

    Answer

    55

  30. 30
    The UUID test generates a value using the Ramsey UUID
    _____
    method.
    Hint

    This method generates a version 4 UUID.

    Answer

    uuid4

  31. 31
    Because the Ramsey UUID generator returns an object, the test calls
    _____
    to obtain a string.
    Hint

    This method converts the UUID object into its textual representation.

    Answer

    toString

  32. 32
    The UUID getter test checks that the entity returns the same
    _____
    that was assigned to it.
    Hint

    It is the unique identifier generated by the Ramsey library.

    Answer

    UUID

  33. 33
    The User entity's unserialization test supplies its expected field values in an
    _____
    .
    Hint

    This PHP data structure maps field names to values.

    Answer

    array

  34. 34
    The unserialization test checks that the input ID is available through the
    _____
    getter.
    Hint

    This getter retrieves the entity's numeric identifier.

    Answer

    getSequentialId

  35. 35
    The first-name field in the example's expected user data is
    _____
    .
    Hint

    It is the sample value used to check the first-name getter.

    Answer

    Pierre

  36. 36
    The last-name field in the example's expected user data is
    _____
    .
    Hint

    It is the sample value checked using the last-name getter.

    Answer

    Surya

  37. 37
    The unserialization test checks the email field using the entity's
    _____
    getter.
    Hint

    This getter returns the user's email value.

    Answer

    getEmail

  38. 38
    The unserialization test checks the phone field using the entity's
    _____
    getter.
    Hint

    This getter returns the user's phone value.

    Answer

    getPhone

  39. 39
    The unserialization test checks the password field using the entity's
    _____
    getter.
    Hint

    This getter returns the user's password value.

    Answer

    getPassword

  40. 40
    The test checks the stored creation date using the entity's
    _____
    getter.
    Hint

    This getter returns the date the user entity was created.

    Answer

    getCreationDate

  41. 41
    The example uses a real database row's creation date to ensure the test uses the expected
    _____
    .
    Hint

    The concern is the date's representation, not only its value.

    Answer

    format

  42. 42
    If PHPUnit is installed globally, tests can be run by invoking
    _____
    in the terminal.
    Hint

    This is the executable available on the system path after a global installation.

    Answer

    phpunit

  43. 43
    If PHPUnit is installed only in the project, its executable is run from
    _____
    .
    Hint

    Composer places project-local executable binaries in this directory.

    Answer

    vendor/bin/phpunit

  44. 44
    The command-line option used to run a specific test by class and method is
    _____
    .
    Hint

    It narrows the test run to a matching name.

    Answer

    --filter

  45. 45
    To target one method with a filter, the class and method are separated by
    _____
    .
    Hint

    This is PHP's scope resolution operator.

    Answer

    ::

  46. 46
    If a test's expected value differs from the entity's actual value, the assertion
    _____
    .
    Hint

    The test reports that the compared values do not match.

    Answer

    fails

  47. 47
    PHPUnit first uses a project configuration named
    _____
    when it exists.
    Hint

    This is the customized configuration file, rather than the distribution file.

    Answer

    phpunit.xml

  48. 48
    If the customized configuration is absent, PHPUnit falls back to
    _____
    .
    Hint

    It is the distributed default configuration file.

    Answer

    phpunit.xml.dist

  49. 49
    The custom PHPUnit configuration and generated test cache are typically excluded from version control using
    _____
    .
    Hint

    This file lists files and directories Git should ignore.

    Answer

    .gitignore

  50. 50
    The automatically generated PHPUnit cache is stored in the
    _____
    directory.
    Hint

    Its name begins with a dot and identifies PHPUnit's cache.

    Answer

    .phpunit.cache

  51. 51
    Composer package files can be excluded from exported archives by adding
    _____
    to .gitattributes.
    Hint

    This attribute tells Git to omit matching paths from an exported archive.

    Answer

    export-ignore

  52. 52
    The test directory is a candidate for exclusion from a distributed package archive because it is unnecessary for the
    _____
    product.
    Hint

    It refers to the product delivered to package users.

    Answer

    shipped

  53. 53
    The session token and last session time columns are not tested yet because they have not been
    _____
    in the User entity.
    Hint

    The entity does not currently retrieve or support these fields.

    Answer

    implemented

1 of 53
Question 1 of 53

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent