Skip to content

Commit c0b7deb

Browse files
authored
Merge pull request #171 from wayofdev/feat/factories
feat!: add laravel factories
2 parents ec3b439 + 810c15d commit c0b7deb

40 files changed

+1202
-178
lines changed

.env.example

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
2+
# With custom namespace provided, it will be used to prefix all services
3+
# in Docker network for current project
4+
COMPOSE_PROJECT_NAME=laravel-cycle-orm-adapter
5+
6+
DB_CONNECTION=pgsql
7+
DB_HOST=pgsql
8+
DB_PORT=5432
9+
10+
DB_DATABASE=default
11+
DB_USERNAME=root
12+
DB_PASSWORD=password
13+
14+
DB_MYSQL_FORWARD_PORT=13306
15+
DB_PGSQL_FORWARD_PORT=15432
16+
17+
XDEBUG_MODE=coverage

.github/workflows/ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,26 @@ jobs:
4242
if: steps.cached-composer-dependencies.outputs.cache-hit != 'true'
4343
run: composer install
4444

45+
- name: 🛠️ Prepare environment
46+
run: |
47+
mkdir -p ./.build/php-cs-fixer
48+
mkdir -p ./.build/phpstan
49+
mkdir -p ./.build/phpunit
50+
4551
- name: 🚨 Run coding standards task
46-
run: make cs-diff
52+
run: composer cs:diff
4753
env:
4854
PHP_CS_FIXER_IGNORE_ENV: true
4955

5056
- name: 🧪 Execute phpunit tests
5157
env:
5258
XDEBUG_MODE: coverage
53-
run: vendor/bin/phpunit --coverage-clover=coverage.xml
59+
DB_CONNECTION: sqlite
60+
DB_DATABASE: ":memory:"
61+
run: vendor/bin/pest --coverage-clover=coverage.xml
5462

5563
- name: 📝 Run static analysis using phpstan
56-
run: make stan
64+
run: composer stan:ci
5765

5866
- name: 📤 Upload coverage report to Codecov
5967
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/vendor/
22
/.build/
3+
.env
4+
coverage.xml

Makefile

Lines changed: 114 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
# leave empty to disable
2-
# -v - verbose;
3-
# -vv - more details
4-
# -vvv - enable connection debugging
5-
DEBUG_VERBOSITY ?=
1+
-include .env
62

7-
DOCKER_CMD =
3+
# BuildKit enables higher performance docker builds and caching possibility
4+
# to decrease build times and increase productivity for free.
5+
# https://docs.docker.com/compose/environment-variables/envvars/
6+
export DOCKER_BUILDKIT ?= 1
87

9-
COMPOSER_RUN = $(DOCKER_CMD) composer
8+
# Binary to use, when executing docker-compose tasks
9+
DOCKER_COMPOSE ?= docker compose
1010

11+
# Support image with all needed binaries, like envsubst, mkcert, wait4x
12+
SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest
13+
14+
APP_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app
15+
APP_COMPOSER ?= $(APP_RUNNER) composer
16+
17+
BUILDER_PARAMS ?= docker run --rm -i \
18+
--env-file ./.env \
19+
--env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
20+
--env COMPOSER_AUTH="$(COMPOSER_AUTH)"
21+
22+
BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE)
23+
BUILDER_WIRED ?= $(BUILDER_PARAMS) --network project.$(COMPOSE_PROJECT_NAME) $(SUPPORT_IMAGE)
24+
25+
# Shorthand envsubst command, executed through build-deps
26+
ENVSUBST ?= $(BUILDER) envsubst
27+
28+
EXPORT_VARS = '\
29+
$${COMPOSE_PROJECT_NAME} \
30+
$${COMPOSER_AUTH}'
31+
32+
33+
# Self documenting Makefile code
34+
# ------------------------------------------------------------------------------------
1135
ifneq ($(TERM),)
1236
BLACK := $(shell tput setaf 0)
1337
RED := $(shell tput setaf 1)
@@ -32,6 +56,8 @@ endif
3256
MAKE_LOGFILE = /tmp/wayofdev-laravel-cycle-orm-adapter.log
3357
MAKE_CMD_COLOR := $(BLUE)
3458

59+
default: all
60+
3561
help:
3662
@echo 'Management commands for package:'
3763
@echo 'Usage:'
@@ -45,62 +71,111 @@ help:
4571
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
4672
.PHONY: help
4773

74+
.EXPORT_ALL_VARIABLES:
75+
76+
# Default action
77+
# Defines default command when `make` is executed without additional parameters
78+
# ------------------------------------------------------------------------------------
4879
all: install hooks
4980
.PHONY: all
5081

82+
83+
# System Actions
84+
# ------------------------------------------------------------------------------------
85+
env: ## Generate .env file from example, use `make env force=true`, to force re-create file
86+
ifeq ($(FORCE),true)
87+
@echo "${YELLOW}Force re-creating .env file from example...${RST}"
88+
$(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
89+
else ifneq ("$(wildcard ./.env)","")
90+
@echo ""
91+
@echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}"
92+
else
93+
@echo "Creating .env file from example"
94+
$(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
95+
endif
96+
.PHONY: env
97+
5198
prepare:
5299
mkdir -p .build/php-cs-fixer
53100
.PHONY: prepare
54101

55102

103+
# Docker Actions
104+
# ------------------------------------------------------------------------------------
105+
up: # Creates and starts containers, defined in docker-compose and override file
106+
$(DOCKER_COMPOSE) up --remove-orphans -d
107+
.PHONY: up
108+
109+
down: # Stops and removes containers of this project
110+
$(DOCKER_COMPOSE) down --remove-orphans --volumes
111+
.PHONY: down
112+
113+
restart: down up ## Runs down and up commands
114+
.PHONY: restart
115+
116+
clean: ## Stops containers if required and removes from system
117+
$(DOCKER_COMPOSE) rm --force --stop
118+
.PHONY: clean
119+
120+
ps: ## List running project containers
121+
$(DOCKER_COMPOSE) ps
122+
.PHONY: ps
123+
124+
logs: ## Show project docker logs with follow up mode enabled
125+
$(DOCKER_COMPOSE) logs -f
126+
.PHONY: logs
127+
128+
pull: ## Pull and update docker images in this project
129+
$(DOCKER_COMPOSE) pull
130+
.PHONY: pull
131+
132+
ssh: ## Login inside running docker container
133+
$(APP_RUNNER) sh
134+
.PHONY: ssh
135+
136+
56137
# Composer
57138
# ------------------------------------------------------------------------------------
58139
install: ## Installs composer dependencies
59-
$(COMPOSER_RUN) install
140+
$(APP_COMPOSER) install
60141
.PHONY: install
61142

62143
update: ## Updates composer dependencies by running composer update command
63-
$(COMPOSER_RUN) update
144+
$(APP_COMPOSER) update
64145
.PHONY: update
65146

66147

67-
# Testing
148+
# Code Quality, Git, Linting, Testing
68149
# ------------------------------------------------------------------------------------
69-
cs-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied
70-
$(COMPOSER_RUN) cs-diff
71-
.PHONY: cs-diff
150+
hooks: ## Install git hooks from pre-commit-config
151+
pre-commit install
152+
pre-commit autoupdate
153+
.PHONY: hooks
154+
155+
lint-yaml: ## Lints yaml files inside project
156+
yamllint .
157+
.PHONY: lint-yaml
158+
159+
lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer
160+
$(APP_COMPOSER) cs:fix
161+
.PHONY: lint-php
72162

73-
cs-fix: prepare ## Fixes code to follow coding standards using php-cs-fixer
74-
$(COMPOSER_RUN) cs-fix
75-
.PHONY: cs-fix
163+
lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied
164+
$(APP_COMPOSER) cs:diff
165+
.PHONY: lint-diff
76166

77-
stan: ## Runs phpstan – static analysis tool
78-
$(COMPOSER_RUN) stan
79-
.PHONY: stan
167+
lint-stan: ## Runs phpstan – static analysis tool
168+
$(APP_COMPOSER) stan
169+
.PHONY: lint-stan
80170

81-
stan-ci:
82-
$(COMPOSER_RUN) stan-ci
83-
.PHONY: stan-ci
171+
lint-stan-ci:
172+
$(APP_COMPOSER) stan:ci
173+
.PHONY: lint-stan-ci
84174

85175
test: ## Run project php-unit and pest tests
86-
XDEBUG_MODE=coverage $(COMPOSER_RUN) test
176+
$(APP_COMPOSER) test
87177
.PHONY: test
88178

89179
test-cc: ## Run project php-unit and pest tests in coverage mode and build report
90-
$(COMPOSER_RUN) test-cc
180+
$(APP_COMPOSER) test:cc
91181
.PHONY: test-cc
92-
93-
94-
# Yaml Actions
95-
# ------------------------------------------------------------------------------------
96-
lint: ## Lints yaml files inside project
97-
yamllint .
98-
.PHONY: lint
99-
100-
101-
# Git Actions
102-
# ------------------------------------------------------------------------------------
103-
hooks: ## Install git hooks from pre-commit-config
104-
pre-commit install
105-
pre-commit autoupdate
106-
.PHONY: hooks

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"illuminate/console": "^10.9",
2727
"illuminate/contracts": "^10.9",
2828
"illuminate/support": "^10.9",
29+
"laminas/laminas-hydrator": "^4.14",
2930
"spiral/attributes": "^3.1",
3031
"symfony/console": "^6.2"
3132
},
@@ -64,12 +65,12 @@
6465
}
6566
},
6667
"scripts": {
67-
"cs-fix": "php vendor/bin/php-cs-fixer fix -v",
68-
"cs-diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
68+
"cs:fix": "php vendor/bin/php-cs-fixer fix -v",
69+
"cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
6970
"test": "php vendor/bin/pest",
70-
"test-cc": "php vendor/bin/pest --coverage",
71+
"test:cc": "php vendor/bin/pest --coverage",
7172
"stan": "php vendor/bin/phpstan analyse --memory-limit=256M",
72-
"stan-ci": "php vendor/bin/phpstan analyse --error-format=github",
73+
"stan:ci": "php vendor/bin/phpstan analyse --error-format=github",
7374
"post-autoload-dump": [
7475
"@php vendor/bin/testbench package:discover --ansi"
7576
]

0 commit comments

Comments
 (0)