-
-
Save saxenap/e8f7ddb8075417d5ed79 to your computer and use it in GitHub Desktop.
new PHP project Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use like that | |
make new AUTHOR="Praveen Saxena" EMAIL="" PROJECT="" PROJECTNAMESPACE="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AUTHOR = AUTHOR | |
EMAIL = EMAIL | |
PROJECT = PROJECT | |
PROJECTNAMESPACE = PROJECTNAMESPACE | |
BUILDFILE = $(PROJECT).phar | |
SRCDIR = src | |
TESTDIR = tests | |
PHPUNITCONFIG = phpunit.xml.dist | |
BOOTSTRAP = bootstrap.php | |
PHPUNIT = vendor/bin/phpunit | |
PHARBUILD = $(shell which phar-build) | |
COMPOSER = $(shell which composer) | |
MAKE = make --no-print-directory | |
define phpunitxml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit backupGlobals="false" | |
backupStaticAttributes="false" | |
colors="true" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
processIsolation="false" | |
stopOnFailure="false" | |
syntaxCheck="false" | |
bootstrap="$(TESTDIR)/$(BOOTSTRAP)" | |
> | |
<testsuites> | |
<testsuite name="All"> | |
<directory suffix="Test.php">./$(TESTDIR)/$(PROJECT)/</directory> | |
</testsuite> | |
</testsuites> | |
<filter> | |
<whitelist> | |
<directory>./$(SRCDIR)/$(PROJECT)/</directory> | |
</whitelist> | |
</filter> | |
</phpunit> | |
endef | |
define bootstrap | |
<?php | |
namespace $(PROJECTNAMESPACE)\Tests { | |
require __DIR__ . '/../vendor/autoload.php'; | |
} | |
endef | |
define composerjson | |
{ | |
"name": "$(shell echo $(AUTHOR) | tr A-Z a-z | tr -d ' ')/$(shell echo $(PROJECT) | tr A-Z a-z | tr -d ' ')", | |
"authors": [ | |
{ | |
"name": "$(AUTHOR)", | |
"email": "$(EMAIL)" | |
} | |
], | |
"minimum-stability": "dev", | |
"prefer-stable": true, | |
"require": { | |
"php": ">=5.4.0" | |
}, | |
"require-dev": { | |
"phpunit/phpunit": "*" | |
}, | |
"autoload": { | |
"psr-4": { | |
"$(PROJECTNAMESPACE)\\": "src/" | |
} | |
}, | |
"autoload-dev": { | |
"psr-4": { | |
"$(PROJECTNAMESPACE)\\Tests\\": "tests/" | |
} | |
} | |
} | |
endef | |
export phpunitxml bootstrap composerjson | |
new: new-composer new-tests new-src | |
tests-run: | |
$(PHPUNIT) --configuration $(PHPUNITCONFIG) | |
keep-tests-running: | |
watch -n $(INTERVAL) -d $(MAKE) tests-run | |
# SRC | |
new-src: | |
$(MAKE) destroy-src | |
@mkdir $(SRCDIR) | |
destroy-src: | |
rm -rf $(SRCDIR) | |
# Composer | |
new-composer: composer-config install-deps | |
composer-config: | |
rm -rf composer.json | |
echo "$$composerjson" >> composer.json | |
install-deps: update-deps | |
$(COMPOSER) --prefer-dist install | |
update-deps: | |
$(COMPOSER) update | |
update-composer: | |
$(COMPOSER) self-update | |
# Tests Init | |
new-tests: tests-dir phpunitxml-config fix-phpunit-persmissions bootstrap | |
tests-dir: | |
$(MAKE) destroy-tests-dir | |
mkdir -p $(SRCDIR) $(TESTDIR) | |
destroy-tests-dir: | |
rm -rf $(TESTDIR) | |
phpunitxml-config: | |
rm -rf $(PHPUNITCONFIG) | |
echo "$$phpunitxml" >> $(PHPUNITCONFIG) | |
fix-phpunit-persmissions: | |
chmod 777 $(PHPUNIT) | |
bootstrap: | |
rm -rf $(TESTDIR)/$(BOOTSTRAP) | |
echo "$$bootstrap" >> $(TESTDIR)/$(BOOTSTRAP) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment