Logo di Php Testing

Php Testing

Organizzazione
OrcaQubits
php-testing

Write PHP tests with PHPUnit — unit tests, mocking, data providers, test doubles, assertions, and TDD practices. Use when writing tests for PHP code, whether in Magento or standalone PHP applications.

Panoramica

AutoreOrcaQubits
Repositoryagentic-commerce-skills-plugins
Nome della skillphp-testing
Stelle
40
Fork
17
File inclusi
Solo istruzioni
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • Tutto nelle istruzioni

    Tutto ciò che serve al modello è nelle istruzioni: nessun file aggiuntivo da sincronizzare.

  • Open source

    Pubblicata da OrcaQubits su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Php Testing in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/OrcaQubits/agentic-commerce-skills-plugins/tree/main/magento2-commerce/skills/php-testing
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Nuova skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella nella cartella delle skill di quell'agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/OrcaQubits/agentic-commerce-skills-plugins.git /tmp/agentic-commerce-skills-plugins
mkdir -p .claude/skills
cp -r /tmp/agentic-commerce-skills-plugins/magento2-commerce/skills/php-testing .claude/skills/php-testing
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Php Testing in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Php Testing non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Php Testing non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

PHP Testing with PHPUnit

Before writing code

Fetch live docs: Web-search site:docs.phpunit.de phpunit 10 (or current version) for the latest PHPUnit documentation. Check https://phpunit.de/ for current version.

PHPUnit Fundamentals

Test Class Structure

  • Test classes extend PHPUnit\Framework\TestCase
  • Test methods prefixed with test or annotated #[Test]
  • setUp() — runs before each test
  • tearDown() — runs after each test
  • setUpBeforeClass() / tearDownAfterClass() — per-class lifecycle

Assertions

Common assertions:

  • assertEquals($expected, $actual) — loose comparison
  • assertSame($expected, $actual) — strict comparison (type + value)
  • assertTrue($value) / assertFalse($value)
  • assertNull($value) / assertNotNull($value)
  • assertInstanceOf($class, $object)
  • assertCount($count, $array)
  • assertArrayHasKey($key, $array)
  • assertStringContainsString($needle, $haystack)
  • expectException($class) — exception testing

Data Providers

Supply multiple test cases to a single test method:

  • #[DataProvider('providerName')] attribute (PHPUnit 10+)
  • Provider method returns array of arrays (each inner array = one test case)
  • Reduces test duplication for parameterized testing

Test Doubles

Mocks

Verify behavior — assert that methods were called with expected arguments:

  • $this->createMock(SomeClass::class)
  • $mock->expects($this->once())->method('save')->with($entity)
  • $mock->expects($this->never())->method('delete')

Stubs

Provide canned responses — no behavior verification:

  • $stub->method('getById')->willReturn($entity)
  • $stub->method('getList')->willReturn($searchResults)

Method Return Behaviors

  • willReturn($value) — always returns this value
  • willReturnMap($map) — returns based on argument mapping
  • willReturnCallback($callable) — dynamic return
  • willThrowException($exception) — throws on call
  • willReturnSelf() — returns the mock (for fluent APIs)

Consecutive Calls

willReturnOnConsecutiveCalls($val1, $val2, $val3) — different return per call.

Note: willReturnOnConsecutiveCalls() is deprecated in PHPUnit 10.3+. Use willReturn() with $this->onConsecutiveCalls() or willReturnCallback() with a counter instead.

Testing Patterns

Arrange-Act-Assert (AAA)

  1. Arrange — set up test data, mocks, dependencies
  2. Act — call the method under test
  3. Assert — verify the result

Testing Exceptions

php
$this->expectException(NoSuchEntityException::class);
$this->expectExceptionMessage('Entity not found');
$repository->getById(999);

Testing Private/Protected Methods

Don't test private methods directly — test through public methods. If a private method is complex enough to test independently, it should probably be extracted to its own class.

Testing with Dependency Injection

Create the class under test with mocked dependencies:

  1. Create mocks for all constructor parameters
  2. Instantiate the class with mocks
  3. Configure mock behavior per test
  4. Call the method and assert

Code Coverage

  • --coverage-html <dir> — generate HTML coverage report
  • --coverage-text — terminal output
  • Focus on meaningful coverage — high-value business logic
  • Don't chase 100% — getters/setters and framework glue don't need coverage

PHPUnit Configuration

phpunit.xml or phpunit.xml.dist:

  • Test suite directories
  • Bootstrap file
  • Coverage filters
  • Environment variables
  • Extensions

Best Practices

  • One assertion per test (or one logical assertion group)
  • Name tests descriptively: testGetByIdThrowsWhenNotFound()
  • Use data providers for parameterized tests
  • Mock external dependencies, not the class under test
  • Keep tests fast — no I/O, no database, no network in unit tests
  • Use setUp() for common test setup
  • Test edge cases: null, empty, boundary values
  • Write the test first (TDD) when practical
  • Run tests before committing

Fetch PHPUnit docs for exact assertion methods, mock API, and configuration options for your PHPUnit version before writing tests.

Domande frequenti

Cosa fa la skill IA Php Testing?

Write PHP tests with PHPUnit — unit tests, mocking, data providers, test doubles, assertions, and TDD practices. Use when writing tests for PHP code, whether in Magento or standalone PHP applications.

Perché usare Php Testing su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Php Testing è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Php Testing in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/OrcaQubits/agentic-commerce-skills-plugins/tree/main/magento2-commerce/skills/php-testing. TypingMind legge il file SKILL.md e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Php Testing?

Qualsiasi modello che colleghi in TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Php Testing?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Php Testing: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Php Testing è gratuita?

Sì. È pubblicata su GitHub da OrcaQubits con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, modelli o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇