Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.0 #5

Merged
merged 13 commits into from Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,33 @@
name: ci

on: [push, pull_request, release]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4']
name: PHP ${{ matrix.php-versions }} Test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring
coverage: xdebug

- name: Validate Composer
run: composer validate --strict

- name: Install Composer Dependencies
run: composer install --no-interaction --prefer-source

- name: Run Tests
run: composer pipeline

- name: Code Coverage
run: bash <(curl -s https://codecov.io/bash)
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@ composer.lock
vendor
*.cache
coverage.xml
Dockerfile
docker-compose.yml
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Rob Waller
Copyright (c) 2020 Rob Waller

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions README.md
@@ -1,26 +1,26 @@
# Atlantic City

[![Build Status](https://travis-ci.org/RobDWaller/atlantic-city.svg?branch=master)](https://travis-ci.org/RobDWaller/atlantic-city) [![codecov](https://codecov.io/gh/RobDWaller/atlantic-city/branch/master/graph/badge.svg)](https://codecov.io/gh/RobDWaller/atlantic-city)
[![Build Status](https://travis-ci.org/RobDWaller/atlantic-city.svg?branch=master)](https://travis-ci.org/RobDWaller/atlantic-city) [![codecov](https://codecov.io/gh/RobDWaller/atlantic-city/branch/master/graph/badge.svg)](https://codecov.io/gh/RobDWaller/atlantic-city) ![PHP Version Support](https://img.shields.io/travis/php-v/RobDWaller/atlantic-city/master)

A Composer based WordPress plugin which displays lyrics from the song Atlantic City in the WordPress admin.
A Composer based WordPress plugin which displays lyrics from the song [Atlantic City](https://en.wikipedia.org/wiki/Atlantic_City_(song)) in the WordPress admin.

This plugin was developed to show how to create WordPress plugins which are hosted on [Packagist](https://packagist.org/) and work with Composer friendly WordPress frameworks like [Dusty](https://packagist.org/packages/rbdwllr/dusty).
This plugin was created to show developers how to create WordPress plugins which are hosted on [Packagist](https://packagist.org/) and work with Composer friendly WordPress frameworks like [Dusty](https://packagist.org/packages/rbdwllr/dusty).

It also highlights how to write unit tests for WordPress plugins using [WP_Mock](https://packagist.org/packages/10up/wp_mock) and how to integrate with code analysis tools like [PHPStan](https://packagist.org/packages/phpstan/phpstan).
It also highlights how to write unit tests for WordPress plugins using [WP_Mock](https://packagist.org/packages/10up/wp_mock) and how to integrate with static analysis tools like [PHPStan](https://packagist.org/packages/phpstan/phpstan).

## Composer Setup

There is only one thing different about a WordPress plugin built with Composer compared to standard PHP packages, which is the package type. With WordPress plugins you set the type to wordpress-plugin in the [Composer.json file](https://github.com/RobDWaller/atlantic-city/blob/master/composer.json).
There is only one difference between a WordPress plugin built with Composer compared to a standard PHP package, which is the package type. With WordPress plugins you set the type to `wordpress-plugin` in the [Composer.json file](https://github.com/RobDWaller/atlantic-city/blob/master/composer.json).

```javascript
```json
"type": "wordpress-plugin",
```

This simply tells Composer friendly WordPress frameworks how to handle the package, instead of putting the package in the vendor folder it will put the package in the WordPress plugins directory. See [WPackagist](https://wpackagist.org/) for more details on this.

## Unit Tests with WP_Mock

To write unit tests for WordPress you need to use a package called [WP_Mock](https://packagist.org/packages/10up/wp_mock). It is an extension of PHP Unit which allows you to mock WordPress' custom function calls.
To write unit tests for WordPress you need to use a package called [WP_Mock](https://packagist.org/packages/10up/wp_mock). It is an extension of PHP Unit which allows you to mock WordPress custom function calls.

For instance this library's [unit tests](https://github.com/RobDWaller/atlantic-city/blob/master/tests/AtlanticCityTest.php) mock the `is_rtl()` function which tells WordPress if the site's text runs from right to left or left to right.

Expand Down Expand Up @@ -54,6 +54,6 @@ WP_Mock::expectActionAdded('action', 'parameters');

## Other Code Analysis Tools

This plugin also integrates with a number of other code analysis tools, including [PHP Code Sniffer](https://packagist.org/packages/squizlabs/php_codesniffer) and [PHP Mess Detection](https://packagist.org/packages/phpmd/phpmd). This will help you improve the quality of the code you produce for WordPress plugins.
This plugin integrates with a number of static analysis tools, including [PHP Code Sniffer](https://packagist.org/packages/squizlabs/php_codesniffer) and [PHP Mess Detection](https://packagist.org/packages/phpmd/phpmd), which will help improve the code quality of the WordPress plugins you produce.

It also shows how you can integrate with [PHPStan](https://phpstan.org) so your code can be statically analysed. This requires a small amount of customisation due to custom WordPress functions. So there is a [configuration file](/phpstan.neon.dist).
It also shows you how to integrate with [PHPStan](https://phpstan.org) to add some type safety to your code. This requires a small amount of customisation to handle WordPress so there is a [configuration file](/phpstan.neon.dist) and an integration with the [szepeviktor/phpstan-wordpress](https://packagist.org/packages/szepeviktor/phpstan-wordpress) package which extends PHPStan for WordPress.
4 changes: 2 additions & 2 deletions atlantic-city.php
@@ -1,14 +1,14 @@
<?php
/**
* @package Atlantic City
* @version 0.1.0
* @version 0.3.0
*
* @wordpress-plugin
* Plugin Name: Atlantic City
* Plugin URI: https://github.com/RobDWaller/atlantic-city
* Description: A Composer based WordPress plugin which displays lyrics from the song Atlantic City in the WordPress admin.
* Author: Rob Waller
* Version: 0.1.0
* Version: 0.3.0
* Author URI: http://rbrt.wllr.info
*/

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -10,14 +10,14 @@
}
],
"require": {
"php": ">=7.1.0"
"php": ">=7.4.0"
},
"require-dev": {
"10up/wp_mock": "^0.4",
"szepeviktor/phpstan-wordpress": "^0.6.3",
"phpmd/phpmd": "2.6.*",
"squizlabs/php_codesniffer": "^3.0",
"phploc/phploc": "^4.0"
"szepeviktor/phpstan-wordpress": "^0.7",
"phpmd/phpmd": "^2.9",
"squizlabs/php_codesniffer": "^3.5",
"phploc/phploc": "^7.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/AtlanticCity.php
Expand Up @@ -54,7 +54,7 @@ private function getLyrics(): array

private function getRandomLyric(): string
{
return $this->getLyrics()[rand(0, 34)];
return $this->getLyrics()[rand(0, count($this->getLyrics()) - 1)];
}

private function getCss(): string
Expand Down