Library
In library mode, your project is a Composer package that ships classes and no executable. Use it for a Behat context, a PHPUnit extension, a framework plugin or a PSR implementation. This page is for developers building a library from Scaffold. Follow it to select the mode and replace the placeholder class with your own.
To select library mode, turn off both entry points, the CLI command app and the CLI script, when you run install.sh:
./install.sh --namespace=AcmeApp --name=acme-app --author="Jane Doe" \
--php --no-php-command --no-php-script
Replace the namespace, name and author with your own. In interactive mode, answer n to both the Use CLI command app and Use simple script prompts.
What you get
install.sh generates the following:
composer.jsonwith the PSR-4 autoloader and nobinsectionsrc/Example.phpandtests/phpunit/Unit/ExampleUnitTest.php, a placeholder class and its test- PHP_CodeSniffer and PHPStan, configured to check
srcandtests/phpunit - Rector, configured to check every PHP file outside
vendorandnode_modules - PHPUnit, configured to report coverage of
src - The
Test PHPGitHub Actions workflow
install.sh leaves out both entry points, box.json, the PHAR build and the Release PHP workflow. A library has no PHAR or script for that workflow to attach.
When Renovate is on, which is the default, install.sh adds a rule to renovate.json so that Renovate skips the require section of composer.json. Those constraints are your package's public contract, so change them by hand.
Add your classes
PHP_CodeSniffer and PHPStan both report an error when neither src nor tests/phpunit holds a PHP file, so add your first class before you delete the placeholders.
To replace the placeholder pair with your classes:
-
Add your classes under
src/, in theAcmeApp\App\namespace.AcmeAppis your--namespacevalue, andAppstays as is. -
Cover each class with a test in
tests/phpunit/Unit/. Give each test class a#[CoversClass]attribute, becausecomposer testfails when a test has no coverage metadata. -
Delete
src/Example.phpandtests/phpunit/Unit/ExampleUnitTest.php. -
Run the tests:
composer testConfirm that every test passes.