Skip to content

Commit

Permalink
fix: all test suites (#148)
Browse files Browse the repository at this point in the history
* fix: test suite

* fix: migrating phpunit config

* fix: I want to see how much is failing

* fix: just trying something

* fix: widen the versions tested against

* fix: not ready for 8.4

* fix: it doesn't fail in Windows 🤔

* fix: carbon dependency

* fix: make it verbose

* fix: make it verbose

* fix: I don't think it will change anything, but who knows

* fix: debug what's happening under the hood

* fix: why the hello yauzl is failing on prefer-lowest 😡

* fix: clean zip maybe ?

* Fix styling

* fix: clean zip maybe ?

* fix: fixed?

* fix: phpstan (level 4)

* fix: cleaning

* feat: composer qa

* fix: renamed test

---------

Co-authored-by: SRWieZ <[email protected]>
  • Loading branch information
SRWieZ and SRWieZ authored Dec 26, 2024
1 parent d5e7c28 commit 8e4f571
Show file tree
Hide file tree
Showing 19 changed files with 465 additions and 374 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'
- '../../phpstan.neon'

jobs:
phpstan:
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.1]
laravel: [10.*]
php: [8.2, 8.1, 8.3]
laravel: [10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: ^8.18
carbon: ^2.67
laravel-package-tools: ^1.16
collision: 7.*
- laravel: 11.*
testbench: 9.*
carbon: "^2.67|^3.0"
laravel-package-tools: ^1.16
collision: ^8.1.1
exclude:
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -41,7 +51,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" "spatie/laravel-package-tools:${{ matrix.laravel-package-tools }}" "nunomaduro/collision:${{ matrix.collision }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --no-interaction
- name: List Installed Dependencies
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ composer.lock
coverage
docs
phpunit.xml
phpstan.neon
vendor
node_modules
resources/js/*.log
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"illuminate/contracts": "^10.0|^11.0",
"laravel/prompts": "^0.1.1|^0.2|^0.3",
"nativephp/laravel": "*",
"nativephp/php-bin": "^0.5",
"nativephp/php-bin": "^0.5.1",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
Expand All @@ -62,6 +62,11 @@
}
},
"scripts": {
"qa": [
"@composer format",
"@composer analyse",
"@composer test"
],
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
Expand Down
Empty file removed phpstan-baseline.neon
Empty file.
4 changes: 0 additions & 4 deletions phpstan.neon.dist → phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includes:
- phpstan-baseline.neon

parameters:
level: 4
paths:
Expand All @@ -10,5 +7,4 @@ parameters:
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false

37 changes: 19 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Native Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
Expand All @@ -33,4 +29,9 @@
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion resources/js/electron-plugin/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
"electron": "<rootDir>/mocks/electron.ts",
"^electron$": "<rootDir>/mocks/electron.ts",
}
};
13 changes: 12 additions & 1 deletion resources/js/electron-plugin/mocks/electron.ts
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
export default {}
module.exports = {
app: {
getPath: jest.fn().mockReturnValue('path'),
isPackaged: jest.fn().mockResolvedValue(function () {
console.log('isPackaged');
return false;
})
},
powerMonitor: {
addListener: jest.fn()
}
}
32 changes: 17 additions & 15 deletions resources/js/electron-plugin/tests/endpoints/clipboard.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import startAPIServer, { APIProcess } from "../../src/server/api";
import axios, { AxiosError } from "axios";
import axios from "axios";
import electron from "electron";

let apiServer: APIProcess;
Expand All @@ -10,18 +10,20 @@ const mockReadImage = {
};

jest.mock('electron', () => ({
clipboard: {
readText: jest.fn(() => 'clipboard text'),
readHTML: jest.fn(() => 'clipboard html'),
readImage: jest.fn(() => mockReadImage),
writeText: jest.fn(),
writeHTML: jest.fn(),
writeImage: jest.fn(),
clear: jest.fn(),
},
nativeImage: {
createFromDataURL: jest.fn(() => 'native image'),
}
...jest.requireActual('electron'),

clipboard: {
readText: jest.fn(() => 'clipboard text'),
readHTML: jest.fn(() => 'clipboard html'),
readImage: jest.fn(() => mockReadImage),
writeText: jest.fn(),
writeHTML: jest.fn(),
writeImage: jest.fn(),
clear: jest.fn(),
},
nativeImage: {
createFromDataURL: jest.fn(() => 'native image'),
}
}));

describe('Clipboard test', () => {
Expand Down Expand Up @@ -65,7 +67,7 @@ describe('Clipboard test', () => {

it('returns an error when trying to write an invalid data URL as image', async () => {
try {
const response = await axios.post('/clipboard/image', {
await axios.post('/clipboard/image', {
image: 'new image data URL',
});
} catch (error) {
Expand All @@ -76,7 +78,7 @@ describe('Clipboard test', () => {
it('can write new images to clipboard', async () => {
const exampleImage = 'example image url';

const response = await axios.post('/clipboard/image', {
await axios.post('/clipboard/image', {
image: exampleImage,
});

Expand Down
21 changes: 9 additions & 12 deletions resources/js/electron-plugin/tests/endpoints/dialog.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import startAPIServer, { APIProcess } from "../../src/server/api";
import axios, { AxiosError } from "axios";
import axios from "axios";
import electron from "electron";

let apiServer: APIProcess;

const mockReadImage = {
isEmpty: jest.fn(() => true),
toDataURL: jest.fn(() => 'clipboard image'),
};

jest.mock('electron', () => ({
dialog: {
showOpenDialogSync: jest.fn(() => ['open dialog result']),
showSaveDialogSync: jest.fn(() => ['save dialog result']),
showMessageBoxSync: jest.fn(() => 1),
showErrorBox: jest.fn(),
}
...jest.requireActual('electron'),

dialog: {
showOpenDialogSync: jest.fn(() => ['open dialog result']),
showSaveDialogSync: jest.fn(() => ['save dialog result']),
showMessageBoxSync: jest.fn(() => 1),
showErrorBox: jest.fn(),
}
}));

describe('Dialog test', () => {
Expand Down
Loading

0 comments on commit 8e4f571

Please sign in to comment.