#112 add unit tests
#112 apply @Chen's fix from JS to PHP