Skip to content

Instantly share code, notes, and snippets.

@michaellihs
Last active November 3, 2017 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellihs/0915e66662ba4182a35f to your computer and use it in GitHub Desktop.
Save michaellihs/0915e66662ba4182a35f to your computer and use it in GitHub Desktop.
Behat in TYPO3

We have an extension PROJECT_NAME-testing, which holds a composer.json like this:

{
    "name": "punktde/PROJECT_NAME-testing",
    "description" : "punkt.de testing suite for PROJECT_NAME",
    "license": "proprietary",
    "repositories": [
        {
            "type": "git",
            "url": "git@gitlab.pluspunkthosting.de:pt/punktde-testing.git"
        }
    ],
    "autoload": {
       "psr-4": {
           "TYPO3\\Flow\\": "vendor/punktde/testing/Classes/PunktDe/Testing"
       }
    },
    "require": {
        "punktde/testing": "dev-master"
    },
    "scripts": {
        "post-update-cmd": "PunktDe\\Testing\\Composer\\InstallerScripts::postUpdateAndInstall",
        "post-install-cmd": "PunktDe\\Testing\\Composer\\InstallerScripts::postUpdateAndInstall"
    },
    "config": {
        "bin-dir": "bin"
    }
}

Inside a generic composer package punktde/testing, we have another composer.json which looks like this:

{
    "name": "punktde/testing",
    "type": "typo3-flow-package",
    "description": "punkt.de Testing",
    "license": "LGPL-3.0+",
    "require": {
        "phpunit/dbunit": ">=1.2",
		"mikey179/vfsStream": "~1",
        "behat/behat": "3.0.11",
        "behat/mink-extension": "2.0.0",
        "behat/mink-selenium2-driver": "*",
        "guzzle/guzzle": "3.9.2"
    },
	"config": {
		"bin-dir": "bin/"
	},
    "autoload": {
        "psr-0": {
            "PunktDe\\Testing": "Classes"
        }
    }
}

that's where Behat is loaded into our extension directory structure. Finally, we get the following directory structure inside the project-specific testing extension:

.
├── Fixtures
├── Tests
│   ├── Behat
│   ├── Functional
│   └── Selenium
├── behat.yml
├── bin
│   ├── phpunit -> ../vendor/phpunit/phpunit/phpunit
│   └── behat -> ../vendor/bin/behat
├── composer.json
├── composer.lock
├── ext_emconf.php
├── ext_icon.gif
├── ext_localconf.php
├── ext_tables.php
└── vendor
    ├── autoload.php
    ├── behat
    ├── bin
    ├── composer
    ├── doctrine
    ├── guzzle
    ├── instaclick
    ├── mikey179
    ├── phpunit
    ├── punktde
    ├── sebastian
    └── symfony

We can now run Behat from within this extension with bin/behat PARAMETERS

Since TYPO3 7 I think you can use composer from the root of your TYPO3 installation - so I would rather put the whole Behat stuff outside any extension and into a testing directory on the same level as your htdocs folder.

Hope, this helps...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment