Menu
Coddy logo textTech

Testing and Integration

Part of the Object Oriented Programming section of Coddy's PHP journey — lesson 87 of 91.

challenge icon

Challenge

Easy

Congratulations on building a complete Library Management System! Now it's time to bring all your components together and verify that everything works seamlessly. You'll create a comprehensive integration test that exercises the full workflow of your library.

You'll organize your code across five files:

  • Book.php — Your Book class with readonly properties (isbn, title, author), a private $isAvailable property, and methods: isAvailable(), markAsBorrowed(), and markAsReturned().
  • User.php — Include the Book file. Your User class with readonly properties (id, name), a private $borrowedBooks array, a MAX_BOOKS constant of 3, and all the user methods.
  • Library.php — Include the User file. Your Library class with book management, borrowing/returning functionality, search methods, and the removeBook() method.
  • Admin.php — Include the Library file. Your Admin class extending User with addBookToLibrary() and removeBookFromLibrary() methods.
  • main.php — Include the Admin file. This is where you'll run your integration test. You'll receive two inputs: a user name and a search author keyword.

    Set up your library system:

    • Create a Library
    • Create an Admin with ID 1 and name "LibraryAdmin"
    • Create a User with ID 2 and the provided user name

    Have the admin add these three books:

    • ISBN: "978-0", Title: "PHP Fundamentals", Author: "Sarah Johnson"
    • ISBN: "978-1", Title: "OOP Patterns", Author: "Mike Chen"
    • ISBN: "978-2", Title: "Web Security", Author: "Sarah Johnson"

    Then run through this integration test sequence, printing each result on a new line:

    1. Have the user borrow "978-0"
    2. Have the user borrow "978-1"
    3. Search by author using the second input and print the count: "Books by author: [count]"
    4. Get available books and print: "Available: [count]"
    5. Have the user return "978-0"
    6. Get available books again and print: "Available after return: [count]"
    7. Have the admin remove "978-0"
    8. Have the admin try to remove "978-0" again

This final challenge validates that your entire system works together — admins managing inventory, users borrowing within limits, searches returning accurate results, and availability updating correctly throughout the workflow.

Try it yourself

<?php

require_once 'Admin.php';

// Read inputs
$userName = trim(fgets(STDIN));
$searchAuthor = trim(fgets(STDIN));

// TODO: Create a Library

// TODO: Create an Admin with ID 1 and name "LibraryAdmin"

// TODO: Create a User with ID 2 and the provided user name

// TODO: Have the admin add three books:
// - ISBN: "978-0", Title: "PHP Fundamentals", Author: "Sarah Johnson"
// - ISBN: "978-1", Title: "OOP Patterns", Author: "Mike Chen"
// - ISBN: "978-2", Title: "Web Security", Author: "Sarah Johnson"

// TODO: Integration test sequence:
// 1. Have the user borrow "978-0"
// 2. Have the user borrow "978-1"
// 3. Search by author using $searchAuthor and print: "Books by author: [count]"
// 4. Get available books and print: "Available: [count]"
// 5. Have the user return "978-0"
// 6. Get available books again and print: "Available after return: [count]"
// 7. Have the admin remove "978-0"
// 8. Have the admin try to remove "978-0" again

?>

All lessons in Object Oriented Programming