From b9502388657982a4975b2da8326c22153ab5ee5c Mon Sep 17 00:00:00 2001
From: Marko <52066939+HeX87@users.noreply.github.com>
Date: Fri, 1 Mar 2024 10:15:12 +0100
Subject: [PATCH] update slack msg
---
.ddev/providers/acquia.yaml | 2 +-
.idea/dataSources.xml | 2 +-
.idea/php.xml | 85 ++++++++++++++++++-
src/EventSubscriber/SlackNotifySubscriber.php | 14 +--
src/Helper/HiltesImport.php | 12 +--
tests/Helper/HiltesImportTest.php | 67 ++++++++-------
6 files changed, 129 insertions(+), 53 deletions(-)
diff --git a/.ddev/providers/acquia.yaml b/.ddev/providers/acquia.yaml
index a9d9716..b3d940a 100755
--- a/.ddev/providers/acquia.yaml
+++ b/.ddev/providers/acquia.yaml
@@ -45,7 +45,7 @@ db_pull_command:
# just using `acli pull:db ${ACQUIA_ENVIRONMENT_ID}`
echo "Using ACQUIA_ENVIRONMENT_ID=${ACQUIA_ENVIRONMENT_ID}"
set -x # You can enable bash debugging output by uncommenting
- db_dump=$(acli pull:db ${ACQUIA_ENVIRONMENT_ID} --no-interaction --no-import | tail -2l | xargs)
+ db_dump=$(acli pull:db ${ACQUIA_ENVIRONMENT_ID} --no-interaction --no-import | tail -2l | xargs | sed 's/^.* //')
ls /var/www/html/.ddev >/dev/null # This just refreshes stale NFS if possible
cp ${db_dump} /var/www/html/.ddev/.downloads/db.sql.gz
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 5179711..346ea4f 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -14,7 +14,7 @@
true
DDEV generated data source
org.mariadb.jdbc.Driver
- jdbc:mariadb://127.0.0.1:55000/db?user=db&password=db
+ jdbc:mariadb://127.0.0.1:60724/db?user=db&password=db
$ProjectFileDir$
diff --git a/.idea/php.xml b/.idea/php.xml
index 3b91bce..3915ff2 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -156,7 +156,10 @@
-
+
+
+
+
+
+
+
+
+ /etc/php/8.1/cli/conf.d/10-mysqlnd.ini, /etc/php/8.1/cli/conf.d/10-opcache.ini, /etc/php/8.1/cli/conf.d/10-pdo.ini, /etc/php/8.1/cli/conf.d/15-xml.ini, /etc/php/8.1/cli/conf.d/20-apcu.ini, /etc/php/8.1/cli/conf.d/20-bcmath.ini, /etc/php/8.1/cli/conf.d/20-bz2.ini, /etc/php/8.1/cli/conf.d/20-calendar.ini, /etc/php/8.1/cli/conf.d/20-ctype.ini, /etc/php/8.1/cli/conf.d/20-curl.ini, /etc/php/8.1/cli/conf.d/20-dom.ini, /etc/php/8.1/cli/conf.d/20-exif.ini, /etc/php/8.1/cli/conf.d/20-ffi.ini, /etc/php/8.1/cli/conf.d/20-fileinfo.ini, /etc/php/8.1/cli/conf.d/20-ftp.ini, /etc/php/8.1/cli/conf.d/20-gd.ini, /etc/php/8.1/cli/conf.d/20-gettext.ini, /etc/php/8.1/cli/conf.d/20-iconv.ini, /etc/php/8.1/cli/conf.d/20-igbinary.ini, /etc/php/8.1/cli/conf.d/20-imagick.ini, /etc/php/8.1/cli/conf.d/20-intl.ini, /etc/php/8.1/cli/conf.d/20-ldap.ini, /etc/php/8.1/cli/conf.d/20-mbstring.ini, /etc/php/8.1/cli/conf.d/20-msgpack.ini, /etc/php/8.1/cli/conf.d/20-mysqli.ini, /etc/php/8.1/cli/conf.d/20-pdo_mysql.ini, /etc/php/8.1/cli/conf.d/20-pdo_pgsql.ini, /etc/php/8.1/cli/conf.d/20-pdo_sqlite.ini, /etc/php/8.1/cli/conf.d/20-pgsql.ini, /etc/php/8.1/cli/conf.d/20-phar.ini, /etc/php/8.1/cli/conf.d/20-posix.ini, /etc/php/8.1/cli/conf.d/20-readline.ini, /etc/php/8.1/cli/conf.d/20-redis.ini, /etc/php/8.1/cli/conf.d/20-shmop.ini, /etc/php/8.1/cli/conf.d/20-simplexml.ini, /etc/php/8.1/cli/conf.d/20-soap.ini, /etc/php/8.1/cli/conf.d/20-sockets.ini, /etc/php/8.1/cli/conf.d/20-sqlite3.ini, /etc/php/8.1/cli/conf.d/20-sysvmsg.ini, /etc/php/8.1/cli/conf.d/20-sysvsem.ini, /etc/php/8.1/cli/conf.d/20-sysvshm.ini, /etc/php/8.1/cli/conf.d/20-tokenizer.ini, /etc/php/8.1/cli/conf.d/20-uploadprogress.ini, /etc/php/8.1/cli/conf.d/20-xmlreader.ini, /etc/php/8.1/cli/conf.d/20-xmlrpc.ini, /etc/php/8.1/cli/conf.d/20-xmlwriter.ini, /etc/php/8.1/cli/conf.d/20-xsl.ini, /etc/php/8.1/cli/conf.d/20-zip.ini, /etc/php/8.1/cli/conf.d/25-memcached.ini
+ /etc/php/8.1/cli/php.ini
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/EventSubscriber/SlackNotifySubscriber.php b/src/EventSubscriber/SlackNotifySubscriber.php
index 964442f..cf52690 100644
--- a/src/EventSubscriber/SlackNotifySubscriber.php
+++ b/src/EventSubscriber/SlackNotifySubscriber.php
@@ -55,7 +55,6 @@ class SlackNotifySubscriber implements EventSubscriberInterface
return;
}
- //if (is_array($order->getData()[0]['positions'] != null)) {
foreach ($order->getData()[0]['positions'] as $item) {
if ($item['menge'] > 0) {
@@ -70,18 +69,16 @@ class SlackNotifySubscriber implements EventSubscriberInterface
]);
$msg = "Bestellung {$order->getOrderId()}: \n";
+ ($item['marke'] ?: $msg .= $item['marke'] . '-');
$msg .= $item['name'];
- $msg .= ' ' . $item['sku'];
+ ($item['han'] ?: $msg .= '-' . $item['han']);
$msg .= ' Menge: ' . $item['menge'] . "\n";
if ($order->getStatus() == 1) {
- $slack->from('CDS-Notify')
- ->send($msg);
+ $slack->from('CDS-Notify')->send($msg);
}
}
}
- // }
-
}
/**
@@ -90,10 +87,6 @@ class SlackNotifySubscriber implements EventSubscriberInterface
*/
private function getWarehouseByGtin(string $gtin)
{
- if ($gtin == null) {
- return false;
- }
-
$product = $this->productRepository->findOneBy(['gtin' => $gtin]);
if ($product) {
@@ -108,5 +101,4 @@ class SlackNotifySubscriber implements EventSubscriberInterface
return null;
}
-
}
\ No newline at end of file
diff --git a/src/Helper/HiltesImport.php b/src/Helper/HiltesImport.php
index 81cbfaf..1d6dbeb 100644
--- a/src/Helper/HiltesImport.php
+++ b/src/Helper/HiltesImport.php
@@ -79,16 +79,8 @@ class HiltesImport
*/
protected function getFiles(bool $delta = false): bool
{
- $finder = Finder::create();
- $finder
- ->in($this->currentDirPath . '/hiltes/h2c/')
- ->depth(0);
-
- if ($delta) {
- $finder->name('/_D/');
- } else {
- $finder->notName('/_D/');
- }
+ $finder = Finder::create()->in($this->currentDirPath . '/hiltes/h2c/')->depth(0);
+ $delta ? $finder->name('/_D/') : $finder->notName('/_D/');
if ($finder->hasResults()) {
foreach ($finder as $file) {
diff --git a/tests/Helper/HiltesImportTest.php b/tests/Helper/HiltesImportTest.php
index 4203bc6..63fb8dc 100644
--- a/tests/Helper/HiltesImportTest.php
+++ b/tests/Helper/HiltesImportTest.php
@@ -15,38 +15,33 @@ use Psr\Log\LoggerInterface;
class HiltesImportTest extends TestCase
{
private $productRepository;
- private $warehouseRepository;
private $stockRepository;
+ private $warehouseRepository;
private $logger;
- private $rootPath;
private $hiltesImport;
protected function setUp(): void
{
$this->productRepository = $this->createMock(ProductRepository::class);
- $this->warehouseRepository = $this->createMock(WarehouseRepository::class);
$this->stockRepository = $this->createMock(StockRepository::class);
+ $this->warehouseRepository = $this->createMock(WarehouseRepository::class);
$this->logger = $this->createMock(LoggerInterface::class);
- $this->rootPath = '/';
$this->hiltesImport = new HiltesImport(
$this->productRepository,
$this->warehouseRepository,
$this->stockRepository,
$this->logger,
- $this->rootPath
+ '/path/to/root'
);
}
- public function testStartImportWithNoFiles()
+ public function testStartImportWithNoFiles(): void
{
- $this->expectException(\RuntimeException::class);
- $this->expectExceptionMessage('No Files to Import');
-
- $this->hiltesImport->startImport();
+ $this->assertEquals([], $this->hiltesImport->startImport());
}
- public function testStartImportWithFiles()
+ public function testStartImportWithFiles(): void
{
// Mock the getFiles method to return true
$hiltesImport = $this->getMockBuilder(HiltesImport::class)
@@ -55,44 +50,58 @@ class HiltesImportTest extends TestCase
$this->warehouseRepository,
$this->stockRepository,
$this->logger,
- $this->rootPath
+ '/path/to/root'
])
->onlyMethods(['getFiles'])
->getMock();
$hiltesImport->method('getFiles')->willReturn(true);
- $this->assertNull($hiltesImport->startImport());
+ $this->assertIsArray($hiltesImport->startImport());
}
- public function testGetFilesWithNoResults()
+ public function testSaveDataWithInvalidData(): void
{
- $this->assertFalse($this->hiltesImport->getFiles());
+ $this->assertFalse($this->hiltesImport->saveData([]));
}
- public function testSaveDataWithNoWarehouse()
+ public function testSaveDataWithValidData(): void
{
- $this->logger->expects($this->once())
- ->method('error')
- ->with('No Warehouse');
+ $this->productRepository->method('findOneBy')->willReturn(new Product());
+ $this->warehouseRepository->method('findOneBy')->willReturn(new Warehouse());
- $this->assertFalse($this->hiltesImport->saveData(['product1', '100']));
+ $this->assertTrue($this->hiltesImport->saveData(['1234567890123', '100', '', 'Warehouse1']));
}
- public function testSaveDataWithValidData()
+ public function testCheckProductWithExistingProduct(): void
+ {
+ $product = new Product();
+ $product->setGtin('1234567890123');
+ $this->productRepository->method('findOneBy')->willReturn($product);
+
+ $this->assertEquals($product->getId(), $this->hiltesImport->checkProduct('1234567890123'));
+ }
+
+ public function testCheckProductWithNewProduct(): void
+ {
+ $this->productRepository->method('findOneBy')->willReturn(null);
+
+ $this->assertNull($this->hiltesImport->checkProduct('1234567890123'));
+ }
+
+ public function testCheckWarehouseNameWithExistingWarehouse(): void
{
$warehouse = new Warehouse();
$warehouse->setName('Warehouse1');
-
- $product = new Product();
- $product->setGtin('product1');
-
$this->warehouseRepository->method('findOneBy')->willReturn($warehouse);
- $this->productRepository->method('findOneBy')->willReturn($product);
- $this->stockRepository->expects($this->once())
- ->method('save');
+ $this->assertEquals($warehouse, $this->hiltesImport->checkWarehouseName('Warehouse1'));
+ }
- $this->assertTrue($this->hiltesImport->saveData(['product1', '100', '', 'Warehouse1']));
+ public function testCheckWarehouseNameWithNewWarehouse(): void
+ {
+ $this->warehouseRepository->method('findOneBy')->willReturn(null);
+
+ $this->assertInstanceOf(Warehouse::class, $this->hiltesImport->checkWarehouseName('Warehouse1'));
}
}
\ No newline at end of file