Testing Under the Test Pyramids



Tech'n'Drinks Meetup (@myposterde)
Munich - 2018-02-28
Michael Haeuslmann (@michaelhaeu)

PHP Meetup (March 28th)


Developing in Symfony 4

Victoria Quirante, limenius.com


The Myth of Untestable Code

Sebastian Heuer, kartenmacherei.de


Chip, St.-Martin-Straße 66-68







What do we test?

Unit Tests

Integration Tests

E2E Tests

Why do we test?

  • input should be mapped to the correct output



Is that really it?

What else do we test?

What's important to us?

Do we test how we build our software?

How do we document our software?

How is our software delivered/backed-up?

I. Architecture

How software is being made

Software Evolution

(aka "historisch gewachsen")

Architecture is the stuff that's hard to change

Architecture is about reducing complexity

Architecture needs to be tested

Do it yourself?
grep, AST, ...?
We need some tools!

dePHPend

Visualizations & Assertions


λ wget http://phar.dephpend.com/dephpend.phar -O ~/bin/dephpend
λ dephpend --help
      _      _____  _    _ _____               _
     | |    |  __ \| |  | |  __ \             | |
   __| | ___| |__) | |__| | |__) |__ _ __   __| |
  / _` |/ _ \  ___/|  __  |  ___/ _ \ _ \ / _` |
 | (_| |  __/ |    | |  | | |  |  __/ | | | (_| |
  \__,_|\___|_|    |_|  |_|_|   \___|_| |_|\__,_| version 0.4

 Usage: ...
λ dephpend text ~/workspace/dephpend/src
Mihaeu\PhpDependencies\Util\AbstractMap --> Mihaeu\PhpDependencies\Util\Collection
Mihaeu\PhpDependencies\Util\DI --> Mihaeu\PhpDependencies\Analyser\Analyser
...

                    

Visualizations

      

<?php

$cmd = shell_exec('dephpend text src --no-classes');
$constraints = [
    'Model.* --> .*View',
    'View.*  --> .*Model',
];
$regex = '/('.implode(')|(', $constraints).')/x';

if (preg_match($regex, $cmd)) {
    echo 'Architecture violation'.PHP_EOL;
    exit(1);
}
                    


https://github.com/mihaeu/dephpend

Whatever you end up using:

Test your architecture!

Metrics

  • number of dependencies, dependents

  • package size

  • abstractness of code

pmd and PhpInspectionsEa to detect other architectural smells

  • gives you hints along the way

  • too many dependencies in a class

  • inheritance hierarchy too deep

  • static calls

https://phpmd.org/ https://github.com/kalessil/phpinspectionsea

JavaScript implementation due in June(-ish)

II. Documentation

And there's an API ...

Plaintext

Style Checks

github.com/btford/write-good

Markdown Linters

github.com/remarkjs/remark-lint

Build and Verify Glossaries

vi /usr/share/dict/project-glossary-english

III. Deployment/Backup

"If you don't test your backups properly there's an excellent chance you won't be able to recover them successfully when you need to."

- Rich Cook
48% of the test recoveries run by companies testing disaster recovery (DR) plans fail

- The Symantec Disaster Recovery Research 2007

IV. Misc

Stop bothering your CI

(and co-workers!)

github.com/sebastianfeldmann/captainhook

Editorconfig


# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4
                    

http://EditorConfig.org

Test it!

github.com/editorconfig-checker/editorconfig-checker.javascript

Thanks!!!



@michaelhaeu




Stock photos from pexels.com

PHP Meetup (March 28th)


Developing in Symfony 4

Victoria Quirante, limenius.com


The Myth of Untestable Code

Sebastian Heuer, kartenmacherei.de


Chip, St.-Martin-Straße 66-68