Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHPUnit for PeachPie projects

License

NotificationsYou must be signed in to change notification settings

peachpiecompiler/phpunit-testadapter

Repository files navigation

This project implements .NET Test Adapter for PeachPie projects containing PHPUnit tests.

Please explain

PeachPie projects are PHP projects compiled into .NET usingPeachPie. It allows to run the PHP code as a regular .NET language, on top of .NET runtime.Test Adapter is an integration of unit tests into the .NET work flow. You may know it as Visual Studio's Test Explorer or the command line utilitydotnet test.

This all together allows torun, debug, and profile PHPUnit tests on top of .NET runtime, inside the Visual Studio or using other .NET build tools or continuous integration services.

Sample project

The test project will be a .NET executable application (e.g. TargetFrameworknet5.0), compiling the test files (e.g.tests/**.php), and referencing the actual PeachPie/PHP application.

lib.msbuildproj:

<ProjectSdk="Peachpie.NET.Sdk/1.0.5-preview7">  <PropertyGroup>    <TargetFramework>net5.0</TargetFramework>  </PropertyGroup>  <ItemGroup>    <CompileInclude="**/*.php" />    <PackageReferenceInclude="Microsoft.NET.Test.Sdk"Version="16.6.1" />    <PackageReferenceInclude="PHPUnit.TestAdapter"Version="9.2.6-preview7" />  </ItemGroup></Project>

File structure

- src  - Email.php- tests  - EmailTest.php- phpunit.xml- lib.msbuildproj

Usage

  • In Visual Studio:

    Open the project in Visual Studio. Navigate to Test / Test Explorer, and continue by running or debugging the discovered tests.

    test explorer

  • On command line:

    dotnettest

Repository structure

  • src/PHPUnit.TestAdapter - The test adapter for VSTest enabling to run PHPUnit tests fromdotnet test and Test Explorer in Microsoft Visual Studio. The project references PHPUnit package, and utilizes its API to drive tests discovery and tests execution.
  • src/phpunit.phpunit.phar -PHPUnit compiled with Peachpie to a .NET Standard assembly. The filephpunit.phar gets downloaded automatically.
  • src/dotnet-phpunit - An optional command line tooldotnet phpunit that runsPHPUnit on a PeachPie project.

The test adapter can be tested on the following sample:

  • samples/Lib - A simple .NET/PHP application with PHPUnit tests.

Test Adapter for VSTest

To run them from the command line, navigate tosamples/Lib and run:

dotnettest

The output should be similar to this one (possibly preceeded by the build log):

Test run for samples\Lib\bin\Debug\netcoreapp3.1\Lib.dll(.NETCoreApp,Version=v3.1)Microsoft (R) Test Execution Command Line Tool Version 16.6.0Copyright (c) Microsoft Corporation.  All rights reserved.Starting test execution, please wait...A total of 1 test files matched the specified pattern.Test Run Successful.Total tests: 3     Passed: 3 Total time: 4.2106 Seconds

You can also open either of these projects in Microsoft Visual Studio and use theTest Explorer window to inspect the existing tests, run, debug, and profile them.

dotnet phpunit

To testdotnet-phpunit onsamples/Lib (which referencesphpunit.phpunit.phar as a project), just run it using the default launch settings.

To test it, run the following commands in the directorysamples/Lib:

dotnet tool install --global dotnet-phpunitdotnet builddotnet phpunit

Both variants should run PHPUnit with the output similar to this one:

Runner of PHPUnit (© Sebastian Bergmann) on PHP assemblies compiled by PeachpieBuilding "samples\Lib\Lib.msbuildproj"...Opening assembly "samples\Lib\obj\Debug\netstandard2.0\Lib.dll"...Assembly loadedPHPUnit 9.2.6 by Sebastian Bergmann and contributors....                                                                 3 / 3 (100%)Time: 00:00.696, Memory: 39.29 KBOK (3 tests, 3 assertions)

To explicitly disable building of the project (as it's already built), pass the--no-build option todotnet phunit, e.g.:

dotnet phpunit --no-build

If you wish to removedotnet-phpunit from the set of installed tools, run:

dotnet tool uninstall --global dotnet-phpunit

About

PHPUnit for PeachPie projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp