# MockingKit
**Repository Path**: curryluya-github/MockingKit
## Basic Information
- **Project Name**: MockingKit
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-07-06
- **Last Updated**: 2024-07-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## About MockingKit
MockingKit is a Swift SDK that lets you easily mock protocols and classes in `Swift`.
MockingKit lets you create mocks of any protocol or class, after which you can `call` functions, `register` dynamic function results, automatically `record` method invocations, and `inspect` all recorded calls.
MockingKit doesn't require any setup or build scripts, and puts no restrictions on your code or architecture. Just create a mock and you're good to go.
## Installation
MockingKit can be installed with the Swift Package Manager:
```
https://github.com/danielsaidi/MockingKit.git
```
## Getting started
MockingKit lets you create mocks of any protocol or open class.
For instance, consider this simple protocol:
```swift
protocol MyProtocol {
func doStuff(int: Int, string: String) -> String
}
```
With MockingKit, you can easily create a mock implementation of this protocol:
```swift
import MockingKit
class MyMock: Mock, MyProtocol {
// Define a lazy reference for each function you want to mock
lazy var doStuffRef = MockReference(doStuff)
// Functions must then call the reference to be recorded
func doStuff(int: Int, string: String) -> String {
call(doStuffRef, args: (int, string))
}
}
```
You can now use the mock to `register` function results, `call` functions and `inspect` recorded calls.
```swift
// Create a mock instance
let mock = MyMock()
// Register a result to be returned by doStuff
mock.registerResult(for: mock.doStuffRef) { args in String(args.1.reversed()) }
// Calling doStuff will now return the pre-registered result
let result = mock.doStuff(int: 42, string: "string") // => "gnirts"
// You can now inspect calls made to doStuff
let calls = mock.calls(to: \.doStuffRef) // => 1 item
calls[0].arguments // => (42, "string")
calls[0].result // => "gnirts"
mock.hasCalled(\.doStuffRef) // => true
```
For more information, please see the [getting started guide][Getting-Started].
## Documentation
The [online documentation][Documentation] has more information, articles, code examples, etc.
## Demo Application
The demo app lets you explore the library. To try it out, just open and run the `Demo` project.
## Support my work
You can [sponsor me][Sponsors] on GitHub Sponsors or [reach out][Email] for paid support, to help support my [open-source projects][OpenSource].
Your support makes it possible for me to put more work into these projects and make them the best they can be.
## Contact
Feel free to reach out if you have questions or if you want to contribute in any way:
* Website: [danielsaidi.com][Website]
* Mastodon: [@danielsaidi@mastodon.social][Mastodon]
* Twitter: [@danielsaidi][Twitter]
* E-mail: [daniel.saidi@gmail.com][Email]
## License
MockingKit is available under the MIT license. See the [LICENSE][License] file for more info.
[Email]: mailto:daniel.saidi@gmail.com
[Website]: https://www.danielsaidi.com
[GitHub]: https://www.github.com/danielsaidi
[Twitter]: https://www.twitter.com/danielsaidi
[Mastodon]: https://mastodon.social/@danielsaidi
[OpenSource]: https://danielsaidi.com/opensource
[Sponsors]: https://github.com/sponsors/danielsaidi
[Documentation]: https://danielsaidi.github.io/MockingKit
[Getting-Started]: https://danielsaidi.github.io/MockingKit/documentation/mockingkit/getting-started
[License]: https://github.com/danielsaidi/MockingKit/blob/master/LICENSE