Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 26e40b68 authored by Christoph Wurst's avatar Christoph Wurst
Browse files

Fix tests

parent ed407fab
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
        "cs:fix": "php-cs-fixer fix",
        "cs:check": "php-cs-fixer fix --dry-run --diff",
        "lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
        "test": "phpunit --configuration phpunit.unit.xml --fail-on-warning"
        "test": "phpunit --configuration phpunit.unit.xml --fail-on-warning",
        "test:dev": "phpunit --configuration phpunit.unit.xml --fail-on-warning --stop-on-error --stop-on-failure"
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Calendar\Controller;

use InvalidArgumentException;
use OCA\Calendar\AppInfo\Application;
use OCA\Calendar\Exception\ClientException;
use OCA\Calendar\Exception\ServiceException;
use OCA\Calendar\Http\JsonResponse;
@@ -50,12 +51,11 @@ class AppointmentConfigController extends Controller {
	/** @var LoggerInterface */
	private $logger;

	public function __construct(string $appName,
								IRequest $request,
	public function __construct(IRequest $request,
								AppointmentConfigService $appointmentService,
								LoggerInterface $logger,
								?string $userId) {
		parent::__construct($appName, $request);
		parent::__construct(Application::APP_ID, $request);
		$this->appointmentConfigService = $appointmentService;
		$this->userId = $userId;
		$this->logger = $logger;
+21 −13
Original line number Diff line number Diff line
@@ -103,22 +103,29 @@ class AvailabilityGenerator {

		$intervals = [];
		foreach ($applicableSlots as $slot) {
			if ($slot['end'] <= $earliestStart || $slot['start'] >= $latestEnd) {
			if ($slot->getEnd() <= $earliestStart || $slot->getStart() >= $latestEnd) {
				continue;
			}
			$startSlot = max(
				$earliestStart,
				$slot['start']
				$slot->getStart()
			);
			$endSlot = min(
				$latestEnd,
				$slot['end']
				$slot->getEnd()
			);
			$intervals[] = new Interval($startSlot, $endSlot);
		}
		return $intervals;
	}

	/**
	 * @param int $start
	 * @param array $availabilityArray
	 * @param string $timeZone
	 *
	 * @return Interval[]
	 */
	private function filterDates(int $start, array $availabilityArray, string $timeZone): array {
		$tz = new DateTimeZone($timeZone);
		// First, transform all timestamps to DateTime Objects
@@ -144,9 +151,11 @@ class AvailabilityGenerator {
			(new DateTimeImmutable())->setTimezone($tz)->setTimestamp($start + 87600)->setTime(23, 59),
		);

		/** @var Interval[] $applicable */
		$applicable = [];
		/** @var DateTimeImmutable $item */
		foreach ($period as $item) {
			/** @var DateTimeImmutable $item */

			// get the weekday from our item and select the applicable rule
			$weekday = strtoupper(mb_strcut($item->format('D'), 0, 2));
			/** @var DateTimeImmutable[][] $dailyRules */
@@ -158,13 +167,12 @@ class AvailabilityGenerator {
			foreach ($dailyRules as $dailyRule) {
				$dStart = $dailyRule['start'];
				$dEnd = $dailyRule['end'];
				$applicable[] = [
					'start' => $item->setTime((int)$dStart->format('H'), (int)$dStart->format('i'))->getTimestamp(),
					'end' => $item->setTime((int)$dEnd->format('H'), (int)$dEnd->format('i'))->getTimestamp(),
				];
				$applicable[] = new Interval(
					$item->setTime((int)$dStart->format('H'), (int)$dStart->format('i'))->getTimestamp(),
					$item->setTime((int)$dEnd->format('H'), (int)$dEnd->format('i'))->getTimestamp(),
				);
			}
		}
		/** [][] */
		return $applicable;
	}
}
+3 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ use OCP\L10N\IFactory;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use Psr\Log\LoggerInterface;
use function implode;

class MailService {

@@ -134,12 +135,12 @@ class MailService {
				$this->logger->warning('Mail delivery failed for some recipients.');
				foreach ($failed as $fail) {
					$this->logger->debug('Failed to deliver email to ' . $fail);
					throw new ServiceException('Could not send mail for recipient ' . $fail);
				}
				throw new ServiceException('Could not send mail for recipient(s) ' . implode(', ', $failed));
			}
		} catch (Exception $ex) {
			$this->logger->error($ex->getMessage(), ['exception' => $ex]);
			throw new ServiceException('Could not send mail', $ex->getCode(), $ex);
			throw new ServiceException('Could not send mail: ' . $ex->getMessage(), $ex->getCode(), $ex);
		}
	}

+2 −2
Original line number Diff line number Diff line
@@ -50,8 +50,8 @@ class CleanupOutdatedBookingJobTest extends TestCase {
	protected function setUp(): void {
		parent::setUp();

		if (!class_exists(ICalendarQuery::class)) {
			$this->markTestIncomplete();
		if (!interface_exists(ICalendarQuery::class)) {
			self::markTestIncomplete();
		}

		$this->time = $this->createMock(ITimeFactory::class);
Loading