Standalone testing in package repositories

Hi everybody,

I have a created a Neos package in a single Git repository to include in multiple Neos projects. My packages does contain some PHP code, which I would like to test. I already have created unit and functional tests based on neos/buildessentials for packages which are in the same repository as one of my Neos projects. That’s not the point of this topic.

My proplem/question explicitly is about how to test packages in standalone repositories. I already have an solution for unit test. With the following lines in my packages composer.json

  "require-dev": {
    "neos/buildessentials": "^7.3",
    "phpunit/phpunit": "^9.0",
    "mikey179/vfsstream": "2.0.x-dev"
  },
  "config": {
    "vendor-dir": "Packages/Libraries",
    "bin-dir": "bin",
    "allow-plugins": {
      "neos/composer-plugin": true
    }
  }

… I easily can execute composer install and bin/phpunit -c Build/tests/UnitTests.xml and my unit tests work.

But this is the end of my knowledge and I would need some help:

  • How could I execute functional tests in my standalone package?
  • Are there any examples or best practices?

My first idea was to configure some additional composer scripts to create a more realistic folder structure:

    "scripts": {
        "pre-install-cmd": [
            "mkdir -p Packages/Application/My.Package",
            "cp -a Classes Configuration Migrations Resources composer.json Packages/Application/My.Package/"
        ],
        "post-install-cmd": [
            "Neos\\Flow\\Composer\\InstallerScripts::postUpdateAndInstall"
        ]
    }

But it feels so wrong that I would like to ask, if there are better concepts. Or am I totally wrong and nobody except me wants to execute functional tests for a package?

When your dependency is not too hard i personally like to add this to my packages.

composer.json

{
    "require-dev": {
    	"neos/neos": "*",
        "phpunit/phpunit": "^7.1 || ^8.0 || ^9.0",
        "phpstan/phpstan": "^0.12.78"
    },
    "autoload-dev": {
        "psr-4": {
            "Neos\\Fusion\\Form\\Tests\\": "Tests"
        }
    },
    "extra": {
    },
    "scripts": {
        "test:functional": ["vendor/bin/phpunit Tests/Functional"],
        "test:unit": ["vendor/bin/phpunit Tests/Unit"],
        "test:stan": ["vendor/bin/phpstan analyse -l 8 Classes"],
        "test": ["composer install", "composer test:functional", "composer test:unit" ,"composer  test:stan"]
    }
}

.gitignore

composer.lock
Packages
vendor

When you run composer test in the project folder it will install all the needed packages into Vendor and Packages. I would try to only use plain phpunit. If you rely on the Flow testcases you would probably have to run phpunit with the configuration from the distribution.

The example is taken from GitHub - neos/fusion-form which also has a nice github workflow for qs fusion-form/build.yml at master · neos/fusion-form · GitHub

Ah ok, so there is no real “best practice” but each developer does configure the tests for his needs?

More like test should always be as lightweight as feasible as this gives fastest feedback.

The full power of all the tests that run for the flow framework would be overkill for most packages.