Skip to content

Commit

Permalink
[TASK] Make extension compatible to cart version v6.x
Browse files Browse the repository at this point in the history
Resolves: #13
  • Loading branch information
extcode committed May 8, 2019
1 parent adb8ed6 commit d41e607
Show file tree
Hide file tree
Showing 48 changed files with 477 additions and 549 deletions.
118 changes: 69 additions & 49 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,98 @@
cache:
key: "$CI_COMMIT_REF_NAME/$CI_JOB_STAGE"
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_NAME"
paths:
- .composer/
- .php_cs.cache

variables:
COMPOSER_CACHE_DIR: ".composer"
TYPO3_PATH_WEB: "$CI_PROJECT_DIR/.Build/Web"
MYSQL_DATABASE: "typo3"
MYSQL_ROOT_PASSWORD: "joh316"
typo3DatabaseName: "typo3"
typo3DatabaseHost: "mysql"
typo3DatabaseUsername: "root"
typo3DatabasePassword: "joh316"

before_script:
- apk add git --update

stages:
- lint
- test

test:cgl:
image: composer:1.3
stage: test
lint:cgl:
image: composer:1.6
stage: lint
before_script:
- composer remove typo3/cms-core --no-update
- composer install
- composer remove typo3/cms-core --no-update
- composer install --no-progress --no-ansi --no-interaction
script:
- .Build/bin/php-cs-fixer fix --config=Build/.php_cs.dist -v --dry-run --using-cache=no --path-mode=intersection ./

lint:typoscriptcgl:
stage: lint
image: composer:1.6
script:
- pwd
- ls .Build/bin/
- .Build/bin/php-cs-fixer fix --config=Build/.php_cs -v --dry-run --using-cache=no --path-mode=intersection ./
- composer remove typo3/cms-core --no-update
- composer install --no-progress --no-ansi --no-interaction
- .Build/bin/typoscript-lint -c tslint.yaml

lint:yaml:
stage: lint
image: python:alpine3.7
before_script:
- pip install yamllint==1.10.0
script:
- yamllint -c Build/yamllint.yaml Configuration/ Resources/ .travis.yml

lint:php72:
stage: lint
image: php:7.2-alpine
script:
- find . -name \*.php -exec php -l "{}" \;

.test: &test_php
stage: test
services:
- mysql:5
image: php:$DOCKER_TAG
only:
- branches
before_script:
- apk --no-cache add bash curl git mercurial openssh openssl parallel subversion tini
- apk add --no-cache bash curl git mercurial openssh openssl parallel subversion tini
- >
if [[ "$COVERAGE" == "1" ]]; then
apk add --no-cache $PHPIZE_DEPS
pecl install xdebug && docker-php-ext-enable xdebug
fi
- docker-php-ext-install mysqli
- export TYPO3_PATH_WEB="$PWD/.Build/Web"
- export COMPOSER_CACHE_DIR=.composer
- curl -OLs https://composer.github.io/installer.sig
- wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- php composer-setup.php --no-ansi --install-dir=/usr/bin --filename=composer
- php -r "unlink('composer-setup.php'); unlink('installer.sig');"
- composer require typo3/cms="${TYPO3_VERSION}" --update-with-dependencies
- composer require nimut/testing-framework
- composer require typo3/cms-core="${TYPO3_VERSION}"
script:
- .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit
- find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null

# Build in PHP 5.6 and TYPO3 7.6
test:php56:typo3_7:
<<: *test_php
variables:
DOCKER_TAG: 5.6-alpine
TYPO3_VERSION: ^7.6

# Build in PHP 7.0 and TYPO3 7.6
test:php70:typo3_7:
<<: *test_php
variables:
DOCKER_TAG: 7.0-alpine
TYPO3_VERSION: ^7.6

# Build in PHP 7.1 and TYPO3 7.6
test:php71:typo3_7:
<<: *test_php
variables:
DOCKER_TAG: 7.1-alpine
TYPO3_VERSION: ^7.6

# Build in PHP 7.0 and TYPO3 8.7
test:php70:typo3_8:
<<: *test_php
variables:
DOCKER_TAG: 7.0-alpine
TYPO3_VERSION: ^8.7
- >
if [[ "$COVERAGE" == "0" ]]; then
.Build/bin/phpunit -c Build/UnitTests.xml Tests/Unit
fi
- >
if [[ "$COVERAGE" == "1" ]]; then
.Build/bin/phpunit --coverage-clover=phpunit.coverage.xml --log-junit=phpunit.report.xml -c Build/UnitTests.xml Tests/Unit
fi
artifacts:
paths:
- phpunit.coverage.xml
- phpunit.report.xml
expire_in: 1 day
when: always

# Build in PHP 7.1 and TYPO3 8.7
test:php71:typo3_8:
# Build in PHP 7.2 and TYPO3 9.3
test:php72:typo3_9:
<<: *test_php
variables:
DOCKER_TAG: 7.1-alpine
TYPO3_VERSION: ^8.7
DOCKER_TAG: 7.2-alpine
TYPO3_VERSION: ^9.5
COVERAGE: 1
18 changes: 3 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ sudo: false
matrix:
fast_finish: true
include:
- php: 7.1
env: TYPO3_VERSION=^8.7
- php: 7
env: TYPO3_VERSION=^8.7
- php: 7.1
env: TYPO3_VERSION=^7.6
- php: 7
env: TYPO3_VERSION=^7.6
- php: 5.6
env: TYPO3_VERSION=^7.6
- php: 7.2
env: TYPO3_VERSION=^9.5

cache:
directories:
Expand All @@ -41,10 +33,6 @@ before_script:
- export TYPO3_PATH_WEB="$PWD/.Build/Web"

script:
- >
echo;
echo "Running unit tests";
.Build/bin/phpunit --colors -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit/

- >
echo;
Expand All @@ -54,4 +42,4 @@ script:
- >
echo;
echo "Running php-cs-fixer";
.Build/bin/php-cs-fixer fix --config=Build/.php_cs -v --dry-run --using-cache=no --path-mode=intersection ./;
.Build/bin/php-cs-fixer fix --config=Build/.php_cs.dist -v --dry-run --using-cache=no --path-mode=intersection ./;
15 changes: 12 additions & 3 deletions Build/.php_cs → Build/.php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/../');

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
Expand All @@ -20,6 +19,7 @@ return PhpCsFixer\Config::create()
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'phpdoc_no_package' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'no_blank_lines_after_phpdoc' => true,
'array_syntax' => ['syntax' => 'short'],
Expand All @@ -36,4 +36,13 @@ return PhpCsFixer\Config::create()
'phpdoc_no_empty_return' => true,
'phpdoc_trim' => true
])
->setFinder($finder);
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/../')
->exclude('.Build')
->exclude('Documentation')
->exclude('Resources')
->notName('ext_emconf.php')
->notName('ext_localconf.php')
->notName('ext_tables.php')
);
21 changes: 21 additions & 0 deletions Build/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="../.Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../Classes/</directory>
</whitelist>
</filter>
</phpunit>
23 changes: 23 additions & 0 deletions Build/yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends: default

rules:
line-length: disable
document-start: disable
braces:
min-spaces-inside-empty: 1
max-spaces-inside-empty: 1
brackets:
min-spaces-inside-empty: 1
max-spaces-inside-empty: 1
comments:
level: error
min-spaces-from-content: 1
comments-indentation:
level: error
empty-lines:
max: 1
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
indentation:
spaces: 2
45 changes: 0 additions & 45 deletions Changelog

This file was deleted.

74 changes: 74 additions & 0 deletions Classes/Domain/Finisher/Order/DocumentFinisher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Extcode\CartPdf\Domain\Finisher\Order;

class DocumentFinisher extends \Extcode\Cart\Domain\Finisher\AbstractFinisher
{
/**
* @var \Extcode\Cart\Domain\Repository\Order\ItemRepository
*/
protected $orderItemRepository;

/**
* @var \Extcode\Cart\Utility\OrderUtility
*/
protected $orderUtility;

/**
* @param \Extcode\Cart\Domain\Repository\Order\ItemRepository $orderItemRepository
*/
public function injectOrderItemRepository(
\Extcode\Cart\Domain\Repository\Order\ItemRepository $orderItemRepository
) {
$this->orderItemRepository = $orderItemRepository;
}

/**
* @param \Extcode\Cart\Utility\OrderUtility $orderUtility
*/
public function injectOrderUtility(
\Extcode\Cart\Utility\OrderUtility $orderUtility
) {
$this->orderUtility = $orderUtility;
}

public function executeInternal()
{
$orderItem = $this->finisherContext->getOrderItem();

if ($this->settings['autoGenerateDocuments']) {
foreach ($this->settings['autoGenerateDocuments'] as $documentType => $documentData) {
$getterForNumber = 'get' . ucfirst($documentType) . 'Number';
$setterForNumber = 'set' . ucfirst($documentType) . 'Number';
$setterForDate = 'set' . ucfirst($documentType) . 'Date';

if (!$orderItem->$getterForNumber()) {
$documentNumber = $this->orderUtility->getNumber($this->settings, $documentType);

$orderItem->$setterForNumber($documentNumber);
$orderItem->$setterForDate(new \DateTime());
}

$this->generatePdfDocument($orderItem, $documentType);
}

$this->orderItemRepository->update($orderItem);
$this->persistenceManager->persistAll();

$this->finisherContext->setOrderItem($orderItem);
}
}

/**
* @param \Extcode\Cart\Domain\Model\Order\Item $orderItem
* @param string $pdfType
*/
protected function generatePdfDocument(\Extcode\Cart\Domain\Model\Order\Item $orderItem, $pdfType)
{
$pdfService = $this->objectManager->get(
\Extcode\CartPdf\Service\PdfService::class
);

$pdfService->createPdf($orderItem, $pdfType);
}
}

0 comments on commit d41e607

Please sign in to comment.