API Sync Implementation + Testing

by Kevin Pfeifer

About Kevin Pfeifer

  • Web-Developer at in Austria - www.sunlime.at
  • Main work: Wordpress and Drupal
  • Started using CakePHP 3 in 2017 and love it ever since ❤️
  • Joined the Core Team in December 2021
  • Tutorial video series on Youtube

What are we going to learn today?

What are we going to learn today?

  • Read all publicly available repositories from cakephp

What are we going to learn today?

  • Read all publicly available repositories from cakephp
  • Sync them into our app via

What are we going to learn today?

  • Read all publicly available repositories from cakephp
  • Sync them into our app via
    • Github PHP SDK + CakePHP HTTP Client

What are we going to learn today?

  • Read all publicly available repositories from cakephp
  • Sync them into our app via
    • Github PHP SDK + CakePHP HTTP Client
    • Custom Client Class Wrapper of Github PHP SDK + CakePHP HTTP Client

What are we going to learn today?

  • Read all publicly available repositories from cakephp
  • Sync them into our app via
    • Github PHP SDK + CakePHP HTTP Client
    • Custom Client Class Wrapper of Github PHP SDK + CakePHP HTTP Client
  • learn how PHPUnit works and how its connected to CakePHP

What are we going to learn today?

  • Read all publicly available repositories from cakephp
  • Sync them into our app via
    • Github PHP SDK + CakePHP HTTP Client
    • Custom Client Class Wrapper of Github PHP SDK + CakePHP HTTP Client
  • learn how PHPUnit works and how its connected to CakePHP
  • and finally establish patterns how to test either approaches even if you are offline

Lets get our basic setup running

Lets import our database schema

https://cakefest2023.pfiff.me/schema.txt

Migrate and bake everything!


          bin/cake migrations migrate
          bin/cake bake all --everything
        

The Sync

Problems with this implementation

What happens if

Problems with this implementation

What happens if

  • a Branch and/or Repository is deleted from Github?

Problems with this implementation

What happens if

  • a Branch and/or Repository is deleted from Github?
  • we manually add a Branch and/or Repository via the UI and sync?

Problems with this implementation

What happens if

  • a Branch and/or Repository is deleted from Github?
  • we manually add a Branch and/or Repository via the UI and sync?
  • the Github API returns an error/nothing or isn’t available at all?

PHPUnit

  • Basics
  • How its connected to CakePHP

Current service structure

What are we mocking?

Separate sync logic from API calls

What are we mocking?

Tipps while debugging tests

add this at the top your tests if you get a 500 to see the “real” stacktrace

$this->disableErrorHandlerMiddleware();

Tipps while debugging tests

Get an IDE (plugin?) which helps you execute specific tests, so you don’t have to re-execute all tests every time you debug something

Tipps while debugging tests

Generate Code Coverage with this abomination of a command

php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html webroot/coverage

and check http://localhost:8765/coverage/index.html

or even better create a composer command for it

Open questions?

Additional topics

  • How to have consistent code style in CakePHP
  • Static Analysis and CakePHP
  • Upgrade Tool Showcase

Thank you!

Image from Pinterest